Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple description attributes on emums

Tags:

.net

c#-4.0

C# 4.0

If i want to set description for enum i may use DescriptionAttribute form System.ComponentModel;

public enum EnumWithDescription
{
    [Description("EnumDescription1")]
    EE = 1,
    [Description("EnumDescription2")]
    PP
}

but if i need another specific description i may implement my specific attribute and extension method which will return this additional description. e.g:

public enum EnumWithDescription
{

    [MyDescritption("MyDescription1")]
    [Description("EnumDescription1")]
    EE = 1
}

anumValue.MyExtensionMethod(); // return me MyDescritpion stirng value

may be there is some another more simple ways of doing this?

like image 965
juk Avatar asked Apr 21 '26 00:04

juk


1 Answers

You may extend DescriptionAttribute like this:

class ExtraDescriptionAttribute : DescriptionAttribute
    {
        private string extraInfo;
        public string ExtraInfo { get { return extraInfo; } set { extraInfo = value; } }

        public ExtraDescriptionAttribute(string description)
        {
            this.DescriptionValue = description;
            this.extraInfo = "";
        }
    }
like image 159
angularrocks.com Avatar answered Apr 23 '26 16:04

angularrocks.com



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!