Reflection

  • Thread starter Thread starter Jon Turner
  • Start date Start date
J

Jon Turner

Is this possible with reflection ? I want to have multiple variables of the
same class. Each variable would have
an attribute associated with it. The class would be responsible for
performing queries dependent on the attributes
associated to that instance. If so, what would the code look like to read
this variable attribute ?

Many Thanks


For example

[attribute: DB('Table1','Column1')]
CBClass db1 = new (CBClass);

[attribute: DB('Table2','Column2')]
CBClass db2 = new (CBClass);

class CBClass
{
CBClass()
{
// I would initialize this instance with the appropriate data
}



}
 
Jon said:
Is this possible with reflection ? I want to have multiple variables of the
same class. Each variable would have
an attribute associated with it. The class would be responsible for
performing queries dependent on the attributes
associated to that instance.

Unless I misread you, no, this is not possible. You can apply
attributes to an instance field or to a static field, but these
attributes belong to (the type that contains) the field - not to the
value assigned to the field.

If you pass your CBClass constructor a MemberInfo corresponding to the
field that 'owns' it, you can then read the attributes off the
MemberInfo, but it's probably easier to just pass the table/column
strings straight to the CBClass constructor.
For example

[attribute: DB('Table1','Column1')]
CBClass db1 = new (CBClass);

[attribute: DB('Table2','Column2')]
CBClass db2 = new (CBClass);

class CBClass
{
CBClass()
{
// I would initialize this instance with the appropriate data
}

}
 
Back
Top