Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Software bugs are impossible to detect by anybody except the end user.
Posted

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

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...