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

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
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top