在构建我转换为 CoreCLR 的项目时,我遇到了这个错误:
C:\Users\Benjamin\Projects\MiniProfiler\StackExchange.Profiling\SqlTiming.cs(136,25):错误 CS1061:“类型”不包含“IsEnum”的定义并且没有接受第一个参数的扩展方法“IsEnum”可以找到类型为“Type”的(您是否缺少 using 指令或程序集引用?)
对此我感到奇怪的是,我可以在网上找到的所有内容都表明Type
应该可用,而IsEnum
属性应该可用。 Fowler 的反向包搜索在System.Runtime
包中找到Type
,我在dnxcore50
框架中的project.json
中有System.Runtime 4.0.20-*
作为依赖项部分。
但是,编译器错误发生了,dotPeek 还说System.Runtime
包中没有Type
类型。 我错过了什么?
@aggieben ,您可能需要 .GetTypeInfo().IsEnum (GetTypeInfo 是 System.Reflection 命名空间中的扩展方法)。 一堆 Type 的表面区域被移动到 TypeInfo,包括我相信的 IsEnum。 关于 dotPeek,我没有尝试过,但如果我不得不猜测它没有注意 System.Runtime.dll 中的 [assembly: TypeForwardedTo(typeof(Type))] 属性,该属性正在转发到 mscorlib 实现。
谢谢!
请注意,截至 2015 年 8 月 4 日,MSDN 在 Type 下列出了 IsEnum for .Net 4.5/4.6
https://msdn.microsoft.com/en-us/library/System.Type_properties (v=vs.110).aspx
谢谢@stephentoub ,这有帮助!
最有用的评论
@aggieben ,您可能需要 .GetTypeInfo().IsEnum (GetTypeInfo 是 System.Reflection 命名空间中的扩展方法)。 一堆 Type 的表面区域被移动到 TypeInfo,包括我相信的 IsEnum。 关于 dotPeek,我没有尝试过,但如果我不得不猜测它没有注意 System.Runtime.dll 中的 [assembly: TypeForwardedTo(typeof(Type))] 属性,该属性正在转发到 mscorlib 实现。