In the following example “Test that v1 function was called” fails. Is there a way to force call the base implementation of “RunFunction” through an instance of “class V2” ?
class V1
{
public virtual string RunFunction()
{
return "V1";
}
}
class V2 : V1
{
public override string RunFunction()
{
return "V2";
}
}
[Test]
public void TestCall()
{
var v1 = (V1)new V2();
var v2 = new V2();
Assert.IsTrue(v1.RunFunction() == "V1", "Test that v1 function was called");
Assert.IsTrue(v2.RunFunction() == "V2", "Test that v2 function was called");
}
Thanks for looking, guys and gals.
The whole point of class inheritance is that it allows you to override selected base class behavior.
You can use the
basekeyword from withinV2to call into base-class code fromV1, but you cannot do that outside of the class. Just as a quick example of usage:Alternatively you could instantiate an instance of
V1: