Know which Object Create the instance

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,
There are some way to know which object (A) create an instance of object (B)
in the constructor of object (B)?

Thanks.
 
Not to my knowledge but you can easily passe a reference of A to the
constructor of B.

S. L.
 
You can find out which TYPE called the object constructor, but I don't
know how to find out which object instance.

public MyConstructor()
{
System.Diagnostics.StackFrame frame = new
System.Diagnostics.StackFrame(1);
Type callerType = frame.GetMethod().DeclaringType;
}
 

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

Back
Top