I'm using Reflection to create instances of other classes. Assembly y = Assembly.LoadFrom(path); Type t = y.GetType(fileName); object ob = Activator.CreateInstance(t); Where 'fileName' is the binary class name and 'path' is its absolute path. I was trying to
use ArrayList to hold multiple instances of different classes, but I found that ArrayList convert various class instances to its uniform object element. When I retrieve an object from an ArrayList, its no longer the original Class object. I cannot use a Original
class name to cast it since I don't know when and which instance will be retrieved. What should I do deal with this situation? Thanks.
::but I found that ArrayList convert various class instances to its uniform object element "Convert" is a totally wrong term here. It stores references as object refernces - nothing is ever converting the instances. ::What should I do deal with this situation?
Let me formulate this as a query: what do you actually KNOW about the classes you create? I mean, are they descendant from a specific type? Do they implement a specific interface? This is what you could use to cast them back into something more specific when
you retrieve them. Your program MUST have some intrinsic knlwledge todo something with the classes - use this knowlesge.
None
0 Points
17 Posts
how to store and retrieve instance created from Activator.CreateInstance()
Oct 21, 2003 02:08 AM|scorpioy|LINK
Member
20 Points
2877 Posts
Re: how to store and retrieve instance created from Activator.CreateInstance()
Oct 21, 2003 08:58 AM|thona|LINK