Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

using attributes in C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
raju - 25 Mar 2008 09:14 GMT
Hai,

    I am new to Attributes in C#.

   can anybody, explain how to use already created attributes in its
child class.

Thanks and Regards,
Raj.
Lasse Vågsæther Karlsen - 25 Mar 2008 09:21 GMT
> Hai,
>
[quoted text clipped - 5 lines]
> Thanks and Regards,
> Raj.

The question is a bit vague, but I'll post my interpretation of it, and
the answer I can give. If the interpretation doesn't fit what you meant,
please elaborate.

I assume you mean that if you in a base class Base, tag, say, a property
with an attribute, and then in a descendant class wants to find out if a
property has been tagged with the attribute or not.

When you have, say, a PropertyInfo object, and call .IsDefined or
.GetCustomAttributes, there is a second boolean parameter that specifies
wether to include attributes inherited from a base class. If you specify
 true here, you'll get inherited attributes.

However, some attributes are marked as non-inheritable, which means
they'll only appear if you scan an instance of the base class itself.

The purpose of these is typically for class attributes, where it isn't
obvious or even beneficial that a descendant automatically inherits the
attribute, and must in these cases be reapplied to the descendant class
as well.

One such example would be the SerializableAttribute, where a class
specifically needs to say it supports serialization, and can't rely on a
base class having said so once and for all.

Signature

Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3

Marc Gravell - 25 Mar 2008 09:24 GMT
Can you clarify a bit? i.e. are you trying do declare an attribute (and
subclassed attribute), or are you trying to write a standard class/struct
and *use* the existing attributes somehow?

If you could post an example of what you want to do (even if it doesn't
compile/work) it would probably help.

Marc

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.