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

Read Field Attributes by Referenced Instance

P: 2
Hi All

I want to read out the properties of a field by the instance, which is referenced by the corresponding field. I want to read out the attributes.

In a class I wrote the following:
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.  
The two fields create instances of the following class:
Expand|Select|Wrap|Line Numbers
  1. class Bb
  2. {
  3.      {private fields}
  4.  
  5.      public string GetName()
  6.      {
  7.           return (GetMyAttrib.Name) //-> this should return "TestA" or "TestB", dependent of the corresponding instance
  8.      }
  9. }
  10.  
I want to read out the attributes of the fields within the instance of the class Bb to determine which field the present objects is referenced to.
How can I do this?

Or is it possible to inherit the attributes of the fields in A to the corresponding object instance of Bb, so that the attributes are directly binded to the corresponding object?

Thank you
Tom
Apr 2 '09 #1
Share this Question
Share on Google+
1 Reply


tlhintoq
Expert 2.5K+
P: 3,525
I think going for attributes is just the long way around.
Just make a property in clas Bb called Name, and retreive that.

Expand|Select|Wrap|Line Numbers
  1.         public class Bd
  2.         {
  3.             public string Name
  4.             {
  5.                 get;
  6.                 set;
  7.             }
  8.         }
  9.  
  10.         public class Ad
  11.         {
  12.             Bd Flintstone = new Bd();
  13.  
  14.             private string GetName()
  15.             {
  16.                 return Flintstone.Name;
  17.             }
  18.         }
  19.  
  20.  
Apr 2 '09 #2

Post your reply

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