我有一个自定义属性,我想要应用于枚举类型本身,但我无法确定正确的路径,以获得正确的*信息,以暴露属性.
像这样的东西
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
public class MyCustAttribute : Attribute {}
[MyCust()]
[MyCust()]
[MyCust()]/*...and so on...*/
public enum MyEnumType{}
Run Code Online (Sandbox Code Playgroud)
我熟悉从枚举值反映说明DescriptionAttribute的更"习惯"的方法.我一直这样做,没问题.如下面的类型情况.
public enum MyEnumType {
[Description("My First Value")]
First,
[Description("My Second Value")]
Second,
}
Run Code Online (Sandbox Code Playgroud)
我确信这很明显,但我不知道这是否可行.