开发者

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());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜