, , . , , - , , . , . , , , . . , :
public interface IFoo
{
string Execute();
}
:
using (Microsoft.CSharp.CSharpCodeProvider foo = new Microsoft.CSharp.CSharpCodeProvider())
{
var params = new System.CodeDom.Compiler.CompilerParameters();
params.GenerateInMemory = true;
params.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
var res = foo.CompileAssemblyFromSource(params, "public class FooClass : IFoo { public string Execute() { return \"output!\";}}");
var type = res.CompiledAssembly.GetType("FooClass");
IFoo obj = (IFoo)Activator.CreateInstance(type);
obj.Execute();
}
, , , , . , :
IFoo obj = (IFoo)Activator.CreateInstance(type);
obj.Execcute();
, , , . , :
dynamic obj = Activator.CreateDynamicInstance(type);
obj.Execcute();