DescriptionAttribute不允许多次设置。
有没有办法有机会多次将属性或枚举设置为DescriptionAttribute类型。
答案 0 :(得分:1)
解决方案:
public class ExtraDescriptionAttribute : DescriptionAttribute
{
private string extraInfo; public string ExtraInfo { get { return extraInfo; } set { extraInfo = value; } }
public ExtraDescriptionAttribute(string description)
{
this.DescriptionValue = description;
this.extraInfo = String.Empty;
}
}
答案 1 :(得分:0)
您应该调用基类构造函数并删除Description
属性。这还显示了如何设置ExtraInfo
属性。
public class ExtraDescriptionAttribute : DescriptionAttribute
{
public String ExtraInfo { get; private set; }
public ExtraDescriptionAttribute (String description, String extraInfo) : base(description)
{
ExtraInfo = extraInfo;
}
}
现在,description属性如下所示:
[ExtraDescriptionAttribute("Description", "ExtraInfo")]