Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2006

Tip: Looking for answers? Try searching our database.

Reflection questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martin Bischoff - 20 Jul 2006 09:28 GMT
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.
==========

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.