Home

Seems to be an issue using Dump on an object in some cases

The following code snippet is not returning expected results when using the Dump extension on an object cast to an interface it implements, notably an interface with a "new" member hiding a parent member, in this case the Value property.

Only the first group of Dumps and all of the Dumps explicitly on the Value properties are correct.

I've attached an example of the output at the end of this post

void Main()
{
    var     foo      = new Foo();
    IFoo    iFoo     = foo;
    IFooNew iFoorNew = foo;

    updateFoo(foo);

    foo.Value.Dump();
    iFoo.Value.Dump();
    iFoorNew.Value.Dump();

    foo.Dump();
    iFoo.Dump();
    iFoorNew.Dump();

    foo      = new Foo();
    iFoo     = foo;
    iFoorNew = foo;

    updateIFoo(foo);

    foo.Value.Dump();
    iFoo.Value.Dump();
    iFoorNew.Value.Dump();

    foo.Dump();
    iFoo.Dump();
    iFoorNew.Dump(); // dump is not correct

    foo      = new Foo();
    iFoo     = foo;
    iFoorNew = foo;

    updateIFooNew(foo);

    foo.Value.Dump();
    iFoo.Value.Dump();
    iFoorNew.Value.Dump();

    foo.Dump();
    iFoo.Dump();
    iFoorNew.Dump(); // dump is not correct
}

void updateFoo(Foo foo)
{
    "foo".Dump();

    foo.Value = 3;  
}

void updateIFoo(IFoo foo)
{
    "IFoo".Dump();

    foo.Value = 3;
}

void updateIFooNew(IFooNew foo)
{
    "IFooNew".Dump();

    foo.Value = 3;
}

public interface IFoo
{
    int Value { get; set; }
}

public interface IFooNew : IFoo
{
    new int Value { get; set; }
}

public class Foo : IFooNew
{
    public int Value { get; set; }

    int IFooNew.Value { get; set; }

    int IFoo.Value { get; set; }
}

Comments

Sign In or Register to comment.