【发布时间】:2016-07-12 11:18:04
【问题描述】:
我正在尝试使用ASP.NET Core 1.0 在Portable Class Library 中编码,以下指令:
public static void WriteMessage<T>(T value)
{
if (typeof(T).IsEnum)
{
Debug.Print("Is enum")
}
else
{
Debug.Print("Not Is enum")
}
}
但是这段代码无法编译,因为编译器说属性IsEnum 在 Type 上不存在。
有什么建议吗?
【问题讨论】:
-
documentation 说:“如果当前 Type 表示泛型类型或泛型方法定义中的类型参数,则此属性始终返回 false。” this 也可能是相关的
标签: c# enums asp.net-core .net-4.6