开发者

Multiple Description Attribute in c#

DescriptionAttribute not allow to be set multiple times.

Is there any way to have such opportunity to set kind of DescriptionAttribute many times to pr开发者_JS百科operty or enum for example.


Solution:

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;
    }
}


You should be calling the base class constructor and remove the Description property. This also shows how to set the ExtraInfo property.

public class ExtraDescriptionAttribute : DescriptionAttribute
{
    public String ExtraInfo { get; private set; }

    public ExtraDescriptionAttribute (String description, String extraInfo) : base(description)
    {
        ExtraInfo = extraInfo;
    }
}

The description attribute will now look like:

[ExtraDescriptionAttribute("Description", "ExtraInfo")]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜