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
Barry Kelly - 20 Jul 2006 10:06 GMT
> 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

Signature
http://barrkel.blogspot.com/
Kevin Yu [MSFT] - 21 Jul 2006 01:44 GMT
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.)
Kevin Yu [MSFT] - 25 Jul 2006 07:46 GMT
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.)
Martin Bischoff - 25 Jul 2006 08:28 GMT
Thanks to everybody for the information. I will think about another solution
for my problem.
Best regards,
Martin
> Hi Martin,
>
[quoted text clipped - 9 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Kevin Yu [MSFT] - 25 Jul 2006 10:06 GMT
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.)
Adam Benson - 21 Jul 2006 09:33 GMT
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.
==========