1
我正在追查一個NullReferenceException和the official documentation缺乏。C#2.0:MethodBase.GetCurrentMethod()是否可以返回null?
這是C#2.0代碼。在反射
我正在追查一個NullReferenceException和the official documentation缺乏。C#2.0:MethodBase.GetCurrentMethod()是否可以返回null?
這是C#2.0代碼。在反射
看,它看起來像它可以:
[MethodImpl(MethodImplOptions.NoInlining)]
public static MethodBase GetCurrentMethod()
{
StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller;
return RuntimeMethodInfo.InternalGetCurrentMethod(ref lookForMyCaller);
}
和InternalGetCurrentMethod
樣子:
internal static MethodBase InternalGetCurrentMethod(ref StackCrawlMark stackMark)
{
RuntimeMethodHandle currentMethod = RuntimeMethodHandle.GetCurrentMethod(ref stackMark);
if (currentMethod.IsNullHandle())
{
return null;
}
return RuntimeType.GetMethodBase(currentMethod.GetTypicalMethodDefinition());
}
謝謝!我可能會考慮安裝反射器。 – emptyset 2009-11-25 19:22:50