Chals.esp

Hi,

I am inspecting an assembly that has a form, and this form has some controls that are inherited from a BaseForm class.

Using GetFields I get to know its controls. However, the inherited controls do not show. I have set BindingFlags as follows:

BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;

Am I missing something, any ideas

Thanks in advance.


Re: .NET Base Class Library Getting protected controls using reflection

micvos

Controls are declared private by default on a form so you can't find them with reflection. Use the Controls property of the form to find all the present controls.




Re: .NET Base Class Library Getting protected controls using reflection

Chals.esp

Yeah but I would need to create an instance of the form to do that, and I would like to avoid that whenever possible since it may be quite a performance hit.

My bad for not saying it in the first post.

Would it be possible to inspect inherited controls without creating an instance of the form




Re: .NET Base Class Library Getting protected controls using reflection

micvos

Made a little mistake. Private members are returned by using BindingFlags.FlattenHierarchy. just the static private members are not returned.




Re: .NET Base Class Library Getting protected controls using reflection

Chals.esp

Yep I noticed :-/. Thanks for trying to help, though.