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: Visual C# General Getting protected controls through reflection

TaylorMichaelL

Add BindingFlags.FlattenHierarchy to get inherited fields as well. Although if it is a form then you can also just use the Controls property to get all the controls contained in the form.

Michael Taylor - 1/25/07
http://p3net.mvps.org





Re: Visual C# General Getting protected controls through reflection

Chals.esp

Yes, creating an instance of the form would solve the problem, but I would like to avoid that if possible...is there any way to do it without creating the form

Thanks!




Re: Visual C# General Getting protected controls through reflection

TaylorMichaelL

You can use reflection to enumerate the controls that are backed as fields in the form (or its base forms) without creating an instance. However most forms do not create fields for child controls so you'll miss a majority of them. The only way to get the programmatically created controls is to create an instance of the form.

Michael Taylor - 1/29/07
http://p3net.mvps.org





Re: Visual C# General Getting protected controls through reflection

Chals.esp

Thank you :)