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