Multiple Description Attribute in C #

DescriptionAttribute does not allow installing multiple times.

Is there a way to be able to set the DescriptionAttribute type for a property or an enumeration multiple times, for example.

+3
source share
2 answers

Decision:

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
source

You must call the constructor of the base class and remove the property Description. It also shows how to set a property ExtraInfo.

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 this:

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

0
source

Source: https://habr.com/ru/post/1758727/


All Articles