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# / February 2008

Tip: Looking for answers? Try searching our database.

Finding the object instance from the attribute instance

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tobiwan_kenobi - 13 Feb 2008 17:13 GMT
public static InfoAttribute GetInfo(Enum instance)
{
 Type type = instance.GetType();
 MemberInfo[] mis = type.GetMember(instance.ToString(), BindingFlags.Public

     BindingFlags.NonPublic | BindingFlags.Static |
BindingFlags.FlattenHierarchy);

 Type attributeType = typeof(InfoAttribute);
 IList attrs = FindAttributes(false, memberInfo, attributeType);
 InfoAttribute ia = attrs[0] as InfoAttribute;
 return ia;
}

Now that I have a reference to an instance of the attribute for an object.  
How can I get the instance of the object to which the instance of the
attribute is associated?

public static object GetInfo(InfoAttribute attribute)
{
 ...
 return infoObject
}
Marc Gravell - 13 Feb 2008 20:52 GMT
You can't.

First the attribute isn't specific to the instance, and second there
still is no way (that I know of) of tracing back from an attribute to
the declaring member.

Marc
tobiwan_kenobi - 15 Feb 2008 15:13 GMT
> You can't.
>
> First the attribute isn't specific to the instance,

You're right.  The reason I was thinking that they did is because I was
looking at attributes associated with each member of an enumeration.  But
yes, you are right.   An attribute is attached to the class (or to the
static?).

> and second there
> still is no way (that I know of) of tracing back from an attribute to
> the declaring member.

Hmm.  Then, I'm still looking.

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.