C# 2.0: Can MethodBase.GetCurrentMethod() return null?
I'm tracking down a NullRef开发者_开发百科erenceException and the official documentation is lacking.
This is C# 2.0 code.
Looking at Reflector, it looks like it can:
[MethodImpl(MethodImplOptions.NoInlining)]
public static MethodBase GetCurrentMethod()
{
StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller;
return RuntimeMethodInfo.InternalGetCurrentMethod(ref lookForMyCaller);
}
and InternalGetCurrentMethod
looks like:
internal static MethodBase InternalGetCurrentMethod(ref StackCrawlMark stackMark)
{
RuntimeMethodHandle currentMethod = RuntimeMethodHandle.GetCurrentMethod(ref stackMark);
if (currentMethod.IsNullHandle())
{
return null;
}
return RuntimeType.GetMethodBase(currentMethod.GetTypicalMethodDefinition());
}
精彩评论