Results 1 to 5 of 5

Thread: [RESOLVED] Getting Assembly of an instance

  1. #1

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Resolved [RESOLVED] Getting Assembly of an instance

    There are three assemblies: A, B and C.

    A has: class Button.
    B has: instance of Button (call it oButton).
    C has: oButton.

    C wants to have: assembly oButton is in (B).

    How to?

    I know I can get an assembly via a type (e.g.: "System.Reflection.Assembly.GetAssembly(type)"), however, I would like to get an assembly some reference belongs to.

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Getting Assembly of an instance

    Normally, B has a reference to A, therefore C also has to have a reference to A.
    You are right when assuming that you can only get a type (class) through refelection. In order to obtain an instance your C assembly should also have a reference to the assembly that holds the type. You can then marshal your instance or serialize it and transfer from B to C.

  3. #3

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Getting Assembly of an instance

    But there's no other way? C only knowing about the oButton ref and not knowing about B nor A?

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Getting Assembly of an instance

    I can hardly imagine about how exactly C would know about TYPE of the oButton without being referenced to A?
    You can marshal some object from B to C but C would not recognize this object as being of the TYPE from A.

    Well, there is a way. Normally I would not recommend that, but still you can extract the type and get an NEW instance of the object from the assembly without referencing it, but whether you can obtain an existing instance from yet the third assembly - this I don't know.

    Once, I was looking for the way of executing a method from the assembly without referencing it.
    I've found the way (described here) but I don't know whether this way fits your needs.

  5. #5

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Getting Assembly of an instance

    Found another solution. Each call actually starts in an assembly where this object exists. So, i will "drag" an Assembly object as a parameter to it's final destination. Not as good as I hopped it would be, but it's the cleanest and most of all, the fastest way to do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width