我可以确定.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。显然,工作代码不会以“。”开头。 –