我正在追踪 NullReferenceException 和 the official documentation缺乏。
这是 C# 2.0 代码。
最佳答案
看看 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());
}
关于.net - C# 2.0 : Can MethodBase. GetCurrentMethod() 返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1799321/