Force to call virtual base function instead of the overriden one.

Posted by Roberto Sebestyen on Stack Overflow See other posts from Stack Overflow or by Roberto Sebestyen
Published on 2010-06-14T20:51:40Z Indexed on 2010/06/14 21:02 UTC
Read the original article Hit count: 139

Filed under:

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");
    }

© Stack Overflow or respective owner

Related posts about c#