我如何在 C# 中检查类型是否为可为 null 的枚举 像
Type t = GetMyType();
bool isEnum = t.IsEnum; //Type member
bool isNullableEnum = t.IsNullableEnum(); How to implement this extension method?
最佳答案
public static bool IsNullableEnum(this Type t)
{
Type u = Nullable.GetUnderlyingType(t);
return (u != null) && u.IsEnum;
}
关于c# - 检查 Type 实例是否为 C# 中的可空枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2723048/