Inheriting attributes
-
I've developed a simple attribute EwBindSkipAttr which is then used on an abstract member of a class, in the hope that all derived classes which must then implement this member will inherit the attribute on their overriding members. This seems to be correctly implemented...the documentation states that the default is for derived and overriding members to inherit attributes. Here's my simple attribute in use... /// /// Return DDL wrapper for table /// [EwBindSkipAttr] public abstract DataDDL DDL{get;} The problem is that in the derived classes I have behaviour which indicates that the attribute has not been inherited. Any thoughts please? Nursey
-
I've developed a simple attribute EwBindSkipAttr which is then used on an abstract member of a class, in the hope that all derived classes which must then implement this member will inherit the attribute on their overriding members. This seems to be correctly implemented...the documentation states that the default is for derived and overriding members to inherit attributes. Here's my simple attribute in use... /// /// Return DDL wrapper for table /// [EwBindSkipAttr] public abstract DataDDL DDL{get;} The problem is that in the derived classes I have behaviour which indicates that the attribute has not been inherited. Any thoughts please? Nursey
Attributes are inheritted by nature, but code which gets and uses these attributes - like
MemberInfo.GetCustomAttributes
- provide parameters that specify whether or not the calling code wants to get inheritted parameters. What behavior is this that you mention? There's many things that can contribute to problems you're facing. Remember, attributes don't provide functionality to Types, they merely extend the metadata of a Type so that if something asks for it the attribute and its data is returned. Simply attributing your class with a custom attribute certainly won't do anything if nothing asks for it and uses it.Microsoft MVP, Visual C# My Articles