Are attributes inherited?

  • Thread starter Thread starter David Laub
  • Start date Start date
D

David Laub

If I have the following code

[MyAttr]
class XYZ
{
}

class InheritXYZ : XYZ
{
}

Is the [MyAttr] attribute defined for class XYZ automatically also defined
for class InheritXYZ (because InheritXYZ is inherited from XYZ)
 
David said:
If I have the following code

[MyAttr]
class XYZ
{
}

class InheritXYZ : XYZ
{
}

Is the [MyAttr] attribute defined for class XYZ automatically also defined
for class InheritXYZ (because InheritXYZ is inherited from XYZ)
Depends on the Attribute class. Some attributes aren't inherited.
 
See AttributeUsageAttribute class, specifically Inherited property.

-Oleg.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top