Yes, the way it declares 'components' as a local variable is a major pain. I
have no idea why this was done - it makes inheritance a big pain when you
want the base class to do something with the components.
I don't know of a way to get the private variable using reflection.
What I had to do, was define an overridable property, and then the developer
of the inherited class has to override it, and return 'components'. That
way the base class can call the property, and polymorphically, the overriden
version will get called, thus getting the components.
"David Veeneman" <da****@nospam.com (domain is my last name)wrote in
message news:%2****************@TK2MSFTNGP03.phx.gbl...
>I need to get a parent's private variable from within a control. Here's
what I'm doing: I have a control that I want to be able to detect the
presence of a particular (System.ComponentModel) component on the same
form. Components aren't contained in the Form.Controls collection--they are
contained in a private Designer variable called 'components'. So, to detect
the component, I'm going to need to get to that private variable from the
control's parent form.
Does anyone have any sample code to get a private variable from a parent?
I'm new to Reflection, and I'm struggling a bit to sort it out. Thanks.
--
David Veeneman
Foresight Systems