are attributes inherited

  • Thread starter Thread starter Dan Holmes
  • Start date Start date
D

Dan Holmes

Say i have:

[Serializable]
public class A
{

}

public class B : A
{
}

does B need the serializable attribute as well?

dan
 
Attributes are inherited.

But SerializableAttribute has Inherited=false attribute and cannot be
inherited:

[ComVisible(true), AttributeUsage(AttributeTargets.Delegate |
AttributeTargets.Enum | AttributeTargets.Struct |
AttributeTargets.Class, Inherited=false)]
public sealed class SerializableAttribute : Attribute
{
...
}

So B needs this one also.

WBR, Alex Meleta
Blog: http://devkids.blogspot.com

-----Original Message-----
From: Dan Holmes [mailto:[email protected]]
Posted At: Donnerstag, 26. April 2007 22:15
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: are attributes inherited
Subject: are attributes inherited

Say i have:

[Serializable]
public class A
{

}

public class B : A
{
}

does B need the serializable attribute as well?

dan
 
Say i have:
[Serializable]
public class A
{

}

public class B : A
{
}

does B need the serializable attribute as well?

In this case yes. See "AttributeUsageAttribute.Inherited".
 
Say i have:

[Serializable]
public class A
{

}

public class B : A
{

}

does B need the serializable attribute as well?

dan

Well, in this particular case yes, you do. However, the attribute
itself defines if it will be inherited, so you'll have to check the
documentation.
 

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