Reflection. finding parent

  • Thread starter Thread starter Mark Bosley
  • Start date Start date
M

Mark Bosley

building a class that inherits from component. I want to be able to grab a
reference to the object that created this new object. Is there a simple way
in reflection to retrieve this?
 
Mark,
building a class that inherits from component. I want to be able to grab a
reference to the object that created this new object. Is there a simple way
in reflection to retrieve this?

No, there's no way to do that, with or without Reflection. If you need
a reference to the creator, you have to pass it in to the constructor
explicitly.



Mattias
 
many of the windows controls have a property called parent that has a
reference to the container containg the control.
for example one can access the parent container of a windows button with the
following code.

Control myParent=button1.Parent;

even though in the initializecomponent method the parent(or Form) was never
explicitly passed to the button object..

anyone with an idea how to provide the same property to a class derived from
component?
 
Mark Bosley said:
many of the windows controls have a property called parent that has a
reference to the container containg the control.

Yes, but that's an entirely different concept from that of the object
(if any) which was running the code which created the control.
for example one can access the parent container of a windows button with the
following code.

Control myParent=button1.Parent;

even though in the initializecomponent method the parent(or Form) was never
explicitly passed to the button object..

But the button was explicitly added to the parent, so the parent can
call button.Parent = this; during the Add call.
 
Yes, but that's an entirely different concept from that of the object
(if any) which was running the code which created the control.


But the button was explicitly added to the parent, so the parent can
call button.Parent = this; during the Add call.

If you would like to create your class and strongly typed collection to
work exactly like the Control.Parent property and the ControlsCollection
I have created a template and a generator to create the code for you.

To get the template navigate the the "simple code generator" in my
signature, download the program and the template called
"ExcluseCol_Guid_MJL".

--
Michael Lang, MCSD
See my .NET open source projects
http://sourceforge.net/projects/colcodegen (simple code generator)
http://sourceforge.net/projects/dbobjecter (database app code generator)
http://sourceforge.net/projects/genadonet ("generic" ADO.NET)
 
Back
Top