By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,587 Members | 1,168 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,587 IT Pros & Developers. It's quick & easy.

Access field attribute by object instance

P: 2
Hi All

How can I access to the attribute of a field by an object to whom this field references to.

I have defined:
Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3. [MyAttrib(Name="TestA";)]
  4. private Bb testing1 = new Bb();
  5.  
  6. [MyAttrib(Name="TestB";)]
  7. private Bb testing2 = new Bb();
  8. }
  9.  
Now I want to access to 'MyAttrib' within class Bb in the following way:
Expand|Select|Wrap|Line Numbers
  1. class Bb
  2. {
  3. {private fields}
  4.  
  5. public string GetName()
  6. {
  7. return (GetMyAttrib.Name) //-> return "TestA" o "TestB", depending on the field, which references to this object-instance
  8. }
  9. }
Is there any way to do this by reflection.

Or how can the attributes assigned to the object-instances of Bb instead of assigning them to the fields?

Thank you
Tom
Apr 3 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.