Access field attribute by object instance

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TomGo
    New Member
    • Apr 2009
    • 2

    Access field attribute by object instance

    Hi All

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

    I have defined:
    Code:
    class A
    {
    [MyAttrib(Name="TestA";)]
    private Bb testing1 = new Bb();
    
    [MyAttrib(Name="TestB";)]
    private Bb testing2 = new Bb();
    }
    Now I want to access to 'MyAttrib' within class Bb in the following way:
    Code:
    class Bb
    {
    {private fields}
    
    public string GetName()
    {
    return (GetMyAttrib.Name) //-> return "TestA" o "TestB", depending on the field, which references to this object-instance
    }
    }
    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
Working...