This question already has an answer here:
I'm trying to compiling code at runtime, and invoke a non-static method.
The main idea is taken from here: Compiling C# Code at Runtime
But in this example they are using a static method.
Is it possible to create an instance of some object and then invoke some methods with it ?
For example - lets say myClass
has void RunMe()
method:
Assembly assembly = results.CompiledAssembly;
var type = assembly.GetType("ns.myClass");
var obj = Activator.CreateInstance(type); // New instance of myClass
How can I run the equivalent line to obj.RunMe()
?
Aucun commentaire:
Enregistrer un commentaire