區分MethodBase我已經基於如何仿製藥
Dictionary<MethodBase, string>
的關鍵是從MethodBase.GetCurrentMethod渲染緩存。一切工作正常,直到方法明確宣佈。但有一天它出現了:
Method1<T>(string value)
當T得到完全不同的類型時,在Dictionary中進行相同的輸入。
所以我的問題是更好的方法來緩存通用方法的值。 (當然,我可以提供提供GetCache的包裝器,並且遇到泛型類型的等式,但這種方式看起來並不優雅)。
更新 這裏我到底要:
static Dictionary<MethodBase, string> cache = new Dictionary<MethodBase, string>();
static void Method1<T>(T g)
{
MethodBase m1 = MethodBase.GetCurrentMethod();
cache[m1] = "m1:" + typeof(T);
}
public static void Main(string[] args)
{
Method1("qwe");
Method1<Stream>(null);
Console.WriteLine("===Here MUST be exactly 2 entry, but only 1 appears==");
foreach(KeyValuePair<MethodBase, string> kv in cache)
Console.WriteLine("{0}--{1}", kv.Key, kv.Value);
}
你要爲每一組的類型參數或者爲每個物理塊代碼(我的答案)的不同高速緩存條目的不同緩存條目? – SLaks 2009-12-21 14:44:13
這似乎是不可能的。 – SLaks 2009-12-21 16:05:47