我可以確定.Method.MethodHandle.GetFunctionPointer()
對於每個匿名函數都是唯一的嗎? 想做匿名函數的FunctionPointer唯一性
public static T Get<T>(Func<T> getDataCallback) where T : class
{
string cacheID = getDataCallback.Method.MethodHandle.GetFunctionPointer().ToString();
var data = HttpRuntime.Cache.Get(cacheID) as T;
if (data == null)
{
data = getDataCallback();
HttpContext.Current.Cache.Insert(cacheID, data);
}
return data;
}
請解釋你爲什麼想知道。 – Dai
你也可以說這是哪個API。顯然,工作代碼不會以「。」開頭。 –