Runtime: “类型”不包含“IsEnum”的定义

创建于 2015-04-21  ·  3评论  ·  资料来源: dotnet/runtime

在构建我转换为 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 实现。

所有3条评论

@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 ,这有帮助!

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

matty-hall picture matty-hall  ·  3评论

jkotas picture jkotas  ·  3评论

bencz picture bencz  ·  3评论

jamesqo picture jamesqo  ·  3评论

yahorsi picture yahorsi  ·  3评论