开发者

C# 2.0: Can MethodBase.GetCurrentMethod() return null?

开发者 https://www.devze.com 2022-12-12 06:53 出处:网络
I\'m tracking down a NullRef开发者_开发百科erenceException and the official documentation is lacking.

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

精彩评论

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