|
-
July 6th, 2011, 10:59 AM
#1
call method in dynamic object?
Hi, i have some sort of Factory class which creates an instance of another class like so:
Code:
public object setDispatcher ( string obj )
{
this.dispatcher = Activator.CreateInstance(Type.GetType(obj));
return this.dispatcher;
}
//This is how i use the method
object disp = setDispatcher ( "MyClass" );
As parameter i gave the name of the Class which i want to instantiate. It works this far, because the constructor is called of the dynamically created class.
The instance of "MyClass" is now stored in the variable 'disp', but obviously i can't just do this:
disp.aMethod();
Because the compiler doesn't know what class i want to have and what methods it has. So there must be some other way to call the methods??
Anyone any advice on this??
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
|