如何在Enum上使用多个描述属性

时间:2012-10-10 20:24:31

标签: c# enums custom-attributes

我们如何在Enum上定义和使用多个描述属性?

public enum EnumWithDescription
{
    [CustomDescritption("job-view")]
    [Description("analyics-job-view")]
    JobView
}

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

    public MyDescritptionAttribute(string description)
    {
        this.DescriptionValue = description;
        this.extraInfo = "";
    }
}

1 个答案:

答案 0 :(得分:5)

使用AllowMultiple

装饰属性
[AttributeUsage(AllowMultiple = true)]
class MyAttribute : Attribute {}

更多信息:msdn