Attribute Inheritance

By default, custom attributes are not inherited. However, the AttributeUsage attribute can make an attribute inheritable. For the AttributeUsage attribute, set the Inherited option to true to enable inheritance.

Inheriting classes with attributes sometimes can cause interesting behavior. In the following code, ZClass is the base class and YClass is the derived class. Both classes have the PrincipalPermission attribute, which identifies the users or roles that can call functions of a particular class. The PrincipalPermission attribute is inheritable. In the example, ZClass functions are available to managers; YClass function calls are available to accountants. The YClass inherits and does not override MethodA from ZClass. Who ...

Get Programming Microsoft® Visual C#® 2008: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.