I would like to override a virtual base class function on the fly and use this overriden method in application. If I write a basic example class:
partial Class myBase
{
public myBase() {}
public virtual void DoStuff()
{
throw new Exception("this function is not overriden");
}
}
partial Class myDeriv : myBase
{
public myDeriv() {}
}
And now I would like to override myDeriv.DoStuff on the fly. So I create a string code block and compile it using
CSharpCodeProvider.CompileAssemblyFromSource
method. After writing this dll to disk I tried to load it using
Assembly.LoadFrom("onTheFly.dll");
But application fails to find this overridden function. If you have any other better solutions I'm open to them also.. I just need to override functions on the fly..
Thank you all!