المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Access to field attributes by object instance



C# Programming
04-03-2009, 11:20 AM
Hi All

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

I have defined:

class A
{
[MyAttrib(Name="TestA"http://www.barakasoft.com/script/Forums/Images/smiley_wink.gif]
private Bb testing1 = new Bb();

[MyAttrib(Name="TestB"http://www.barakasoft.com/script/Forums/Images/smiley_wink.gif]
private Bb testing2 = new Bb();
}


Now I want to access to 'MyAttrib' within class Bb in the following way:

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