|
-
Jul 14th, 2011, 03:27 AM
#1
[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.
-
Jul 14th, 2011, 03:52 AM
#2
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.
-
Jul 14th, 2011, 03:55 AM
#3
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?
-
Jul 14th, 2011, 04:47 AM
#4
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.
-
Jul 15th, 2011, 10:18 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|