Are Method Attributes Inherited in C#?

后端 未结 3 1282
闹比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:36

    It depends on the Attribute.

    attributes applied to Attribute class defination, carry a property [AttributeUsageAttribute.Inherited] that determines if an attributed is inherited in the derived classes.

    check out this sample

    [global::System.AttributeUsage(AttributeTargets.Method, Inherited = true, 
         AllowMultiple = false)]
    public sealed class MyAttribute : Attribute
    {
    
        public MyAttribute (string FieldName)
        {
            //constructor.
        }
    
    }
    

提交回复
热议问题