我正在追踪NullReferenceException并且缺少the official documentation。
这是C#2.0代码。
答案 0 :(得分:2)
看看Reflector,看起来它可以:
[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());
}