我有一個函數:通功能參數
private static PrivateMessage GetPM()
{
using (var db = new DBContext())
{
var q = CompiledQueries.GetPMByID(db, messageID);
if (q == null) return null;
return new PrivateMessage(q);
}
}
我希望通過這個功能作爲一個參數:
var pm = cacheObj.SetIfNotExists(GetPM);
凡SetIfNotExists
被定義爲:
public T SetIfNotExists<T>(Func<T> getCachableObjectFunction)
什麼是否需要修改,以便我可以通過messageID
作爲參數GetPM()
? EG:
private static PrivateMessage GetPM(int messageID)
變種PM = cacheObj.SetIfNotExists(()=> GetPM(1)); ? – Evk