Are Method Attributes Inherited in C#?

后端 未结 3 1269
闹比i
闹比i 2021-01-01 09:58

Are attributes applied to an abstract method in a base class applied to the overridden versions in the child classes?

I hope the question is clear enough without an

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 10:43

    You can specify that by applying the AttributeUsage attribute to your custom ones, and setting the Inherited property (which is true by default). This property indicates if your attribute can be inherited by classes that are derived from the classes that have your custom attribute applied.

    [AttributeUsage( Inherited = false)]
    public class CustomAttribute : Attribute
    {
    }
    

    Recommended read:

    • Writing Custom Attributes

提交回复
热议问题