PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

are attributes inherited

 
 
Dan Holmes
Guest
Posts: n/a
 
      26th Apr 2007
Say i have:

[Serializable]
public class A
{

}

public class B : A
{
}

does B need the serializable attribute as well?

dan
 
Reply With Quote
 
 
 
 
Alex Meleta
Guest
Posts: n/a
 
      26th Apr 2007
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 [private.php?do=newpm&u=]
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

 
Reply With Quote
 
Larry Smith
Guest
Posts: n/a
 
      26th Apr 2007
> 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".


 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      26th Apr 2007
On Apr 26, 2:15 pm, Dan Holmes <danhol...@bigfoot.com> wrote:
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RenderContents not rendering programmatically set attributes inherited from System.Web.UI.WebControls.Image Nathan Sokalski Microsoft ASP .NET 1 31st Jul 2009 05:44 AM
Are attributes inherited? Dan Holmes Microsoft C# .NET 1 10th Apr 2006 10:26 PM
Custom Attributes - Are they implicitly inherited by subclasses? Lee Microsoft C# .NET 1 3rd Mar 2006 06:17 PM
Are attributes inherited? David Laub Microsoft Dot NET Framework 2 31st Mar 2005 12:19 AM
implementing inherited control re:Ken Tucker - Inherited DataGrid Class Doug Bell Microsoft VB .NET 2 6th Oct 2004 10:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:38 PM.