AttributeUsageAttribute::Inherited Property

 

Gets or sets a Boolean value that determines whether the indicated attribute is inherited by derived classes and overriding members.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public:
property bool Inherited {
	bool get();
	void set(bool value);
}

Property Value

Type: System::Boolean

true if the attribute can be inherited by derived classes and overriding members; otherwise, false. The default is true.

The Inherited property determines:

  • Whether classes derived from a base class tagged with the attribute to which the AttributeUsageAttribute attribute is applied inherit that attribute.

  • Whether methods of derived classes that override a base class method tagged with the attribute to which the AttributeUsageAttribute attribute is applied inherit that attribute. (If a class inherits a base class member, it also inherits any attributes applied to that member.)

The following example illustrates the difference between an attribute to which an AttributeUsageAttribute attribute with an Inherited property value of true is applied and one to which AttributeUsageAttribute attribute with an Inherited property value of true is applied . The example defines two attributes, InheritedAttribute and NotInheritedAttribute. Both attributes can apply to classes and methods. Because the Inherited property of the AttributeUsageAttribute attribute applied to InheritedAttribute is true, it is inherited by derived classes and the members of derived classes that override the base class method. On the other hand, because the Inherited property of the AttributeUsageAttribute attribute applied to NotInheritedAttribute is false, it is not inherited by derived classes and the members of derived classes that override the base class method.

No code example is currently available or this language may not be supported.

The example then defines two base classes. The first, BaseA, has a single method, MethodA. The second, BaseB, has a single method, MethodB. BaseA and MethodA are tagged with the InheritedAttribute attribute, and BaseB and MethodB are tagged with the NotInheritedAttribute attribute. DerivedA inherits from BaseA and overrides its MethodA method. DerivedB inherits from BaseB and overrides its MethodB method.

No code example is currently available or this language may not be supported.

As the output from the example shows, DerivedA and DerivedA.MethodA inherit the InheritedAttribute attribute, but DerivedB and DerivedB.MethodB do not inherit the NotInheritedAttribute attribute.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: