Reflection questions

  • Thread starter Thread starter Martin Bischoff
  • Start date Start date
M

Martin Bischoff

Hi,
if I have two classes, ClassA and ClassB, and ClassA has a member of
type ClassB, is it possible from within ClassB to find out that the
current instance is a member of ClassA?


Example:

class ClassA
{
private ClassB _myClassB = new ClassB();
}

class ClassB
{
public void FindOwner()
{
// is there some way to find out, that this
// instance is a member of an instance of
// ClassA, e.g. using reflection?
}
}


Thanks,
Martin
 
Martin Bischoff said:
if I have two classes, ClassA and ClassB, and ClassA has a member of
type ClassB, is it possible from within ClassB to find out that the
current instance is a member of ClassA?

No, not without a manual brute-force search of the managed object heap.

-- Barry
 
Hi Martin,

I agree with Barry, that we can only see a parent has a certain child. But
we cannot check which parent a child belongs to in a very simple method. As
Barry mentioned, only with a brute-force search, can we get the parent of
certain child.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Errrr.... forgive me if this is a dumb question, but if an object must know
who created it, why not force anything creating that object to supply a
this, i.e. :

class ClassA
{
private ClassB _myClassB;
public ClassA()
{
_myClassB = new ClassB(this);
}
}

class ClassB
{
private object parent;
public ClassB(object daddy)
{
this.parent = daddy
}

public void FindOwner()
{
// Get the info from this.parent
}
}

HTH,

Adam.
==========
 
Hi Martin,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support

==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Thanks to everybody for the information. I will think about another solution
for my problem.

Best regards,
Martin
 
You're welcome, Martin. Please feel free to post in the communtiy if you
need any help.

Kevin Yu
Microsoft Online Community Support

==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top