.net - C# 2.0 : Can MethodBase. GetCurrentMethod() 返回 null?

标签 .net null c#-2.0

我正在追踪 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/

相关文章:

php - 如何将 php 数组中的 null 值转换为空字符串?

c# - null + true 怎么是一个字符串?

themes - 更改 C# Windows 应用程序的主题

c#-2.0 - 如何在 C# 中将两个不同的 xml 文件反序列化为两个不同的类对象?

c# - 如何使用 C# 从 .asc 文件中的特定位置读取数据

.net - 如何检查用户是否在 javascript 中传递了有效日期?

c# - System.Configuration.ConfigurationSettings.AppSettings 在生产中不可访问

c# - 什么是NullReferenceException,如何解决?

c# - 了解 .Net 泛型 - 银行域

c# - C# 中的通用集合算法