I have a base class with some virtual functions
public class ABaseClass
{
public virtual void DoAThing()
{
print("print this base");
}
}
I have another class that inherits from the base class as below.
public class AChildClass : ABaseClass
{
public override void DoAThing()
{
print("child override");
base.DoAThing();
}
}
During run-time I want to instantiate the child class while also wrapping/injecting/overriding a method it overrides in the base class to do as follows. I basically want to add to DoAThing method so that when it is called somewhere else it will do the extra code I added in.
...
//somewhere else I instantiate and override the method at runtime
AChildClass instance = new AChildClass()
{
DoAThing = new method()
{
// Do some extra stuff
print("print this also");
// do child class stuff and base stuff
print("child override")
base.DoAThing(); //print("print this base");
}
}
Is this possible to do in C#?