现在,我正在处理.NET核心类库项目,并测试一些针对.NET框架的常规类库项目中已有的代码。
我安装了System.ComponentModel NuGet包以在enum中使用注释。看来它不认识注释了。
下面是枚举的样子:
using System.ComponentModel;
public enum UserRole
{
[Description("Undefined")]
Undefined = 0,
[Description("Super User")]
SuperUser = 1,
[Description("Administrator")]
Admin = 2,
[Description("Regular User")]
RegUser = 4
}我看到的错误是:
无法找到类型或命名空间名称'DescriptionAttribute‘(您缺少使用指令或程序集引用吗?)
顶部使用的System.ComponentModel引用是灰色的,看起来根本没有被使用。
两个问题:
在我针对.NET Framework4.6.2的类库项目中,代码运行得很好。因此,我只将我知道正在工作的代码转移到我的新的.NET核心类库项目中。
发布于 2017-03-12 04:10:06
对于DescriptionAttribute,您需要使用System.ComponentModel.Primitives包(Version4.1及以上版本)。
这里有一个方便的网站,您可以查找API的包/支持:https://packagesearch.azurewebsites.net/?q=descriptionattribute
https://stackoverflow.com/questions/42743396
复制相似问题