Can I get attributes for a field without a reference to the class that contains it?

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,

I have a method that takes a reference to a TextBox as its only
parameter. I have a custom attribute that may be applied to this
TextBox. Is there a way for me to see if this attribute is present
without having a reference to the class that the TextBox is in?

Is something like this somehow possible?

FieldInfo fi = textbox.GetType().GetFieldInfo();
Attributes []attr = fi.GetCustomAttributes(true)
// check attr for my attribute

THANKS!
John
 
John,
Is there a way for me to see if this attribute is present
without having a reference to the class that the TextBox is in?

No. Just given a Textbox reference, you can't even know that there is
a corresponding field referencing it somewhere. There could be zero or
more such fields.



Mattias
 
Back
Top