AlexCode Posted October 8, 2004 Posted October 8, 2004 Hi. I'm trying to do something I don't know if it's possible... ;) I need to access objects declared on an assembly (class2) from the main class (class1), at runtime, but the only link between them its an Interface. So I don't really know what objects exist on the 'class2'. The class2 implements the Interface. The Interface have 1 method: - Public function GetObject(name as string) as object The implementation of this Interface on class2 goes like the following: For Each obj As Object In Me.GetType.GetFields If TypeOf obj Is System.Reflection.FieldInfo Then If CType(obj, System.Reflection.FieldInfo).Name = "t" & name Then 'Found the FieldInfo End If End If Next So, calling the GetObject function, I can retrieve the FieldInfo of a field inside a class, by reflection, by its name. The problem is that I don't what the field info... I want the actual object. On the NEW of the class2 I instanciate several objects. If class2 were referenced normally, intellisense would just give me the objects, but thru the interface I can't have them that way. I can use the Assembly.CreateInstance but this will create another instance of the same object, not the already created instance on class2. So, is there a way to do this? Thanks, Alex Quote Software bugs are impossible to detect by anybody except the end user.
Administrators PlausiblyDamp Posted October 8, 2004 Administrators Posted October 8, 2004 Have you looked here for a sample in how to dynamically load classes via a standard interface? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
AlexCode Posted October 8, 2004 Author Posted October 8, 2004 That's exactly the way I've been doing it for several months now... The problem is that this way I can only create new objects (classes) and know all the methods in them thru the Interface. What do I have: I have a class that's created thru CodeDOM, compiled at runtime and recognized by the main application as a PlugIn. The methods in the plugin class are variable. I need a way to get them by name. This is crazy I know eheheh, but I'm crazy!, and this crazy idea lets me create a database at runtime, changing the look and functionalities of my application directly on the client. The application builds itself from an XML or sevelar XML files and plugins assemblies... becoming a huge ERP... :p Alex Quote Software bugs are impossible to detect by anybody except the end user.
AlexCode Posted October 11, 2004 Author Posted October 11, 2004 It's donne... I'll post the solution latter on... cool stuf! :p Alex Quote Software bugs are impossible to detect by anybody except the end user.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.