Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我从描述属性中收到以下错误,如下所示:
属性“描述”在此声明类型上无效。它仅对“方法”声明有效。
public enum TestEnum { [Description("Property 1")] Property1, }
我以前从未遇到过这个错误,谷歌并没有透露太多信息。我想这是一个参考问题,但我不确定。
DescriptionAttribute几乎可以应用于任何类型的成员,包括枚举值。你确定你用对了[Description]吗?确保引用它来自的程序集:
DescriptionAttribute
[Description]
using System.ComponentModel;
而且,如果您的范围内碰巧有两个不同的属性称为“描述”,请在其前面加上命名空间以消除歧义,即
enum MyEnum { [System.ComponentModel.Description("Blah")] MyValue }