Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Properties are listed twice in variable, but not in class

Tags:

So I have a simple class that represents data from the database.

public class EntitySyncContext
{
    public EntitySyncContext()
    {
        ExternalEntities = new List<ExternalContact>();
    }
    public HandledType HandledType { get; set; }
    public Contact Entity { get; set; }
    public IList<ExternalContact> ExternalEntities { get; set; }
    public bool HasConflict { get; set; }
}

But when I declare a variable from this class, when I put a watch on it while debugging I see that all of the properties that are listed above exist twice within the variable.

EntitySyncContext matchingContext = new EntitySyncContext();

Printscreen of properties

Does anyone know how and/or why this happens and/or how to fix it?

like image 839
Gravinco Avatar asked Nov 06 '14 13:11

Gravinco


1 Answers

I only have VIsual Studio 2015 installed right now so behavior may be different but it got me thinking about a couple of things.

Look at this code here:

public interface IA
{
    string StringA { get; }
}

public interface IB
{
        string StringA { get; }
}

public class B
{
    public string StringA { get; }
}

public class A : B, IA, IB
{
    public string StringA
    {
        get
        {
            return "A";
        }
    }

    string IB.StringA
    {
        get
        {
            return "B";
        }
    }
}

Here is what watching an instance of class A looks like in Visual Studio 2015:

The watch window of a very weird class

So my thinking is that you have either explicitly implemented interfaces that have the same properties, or you could be hiding properties of a base class by declaring properties by the same name in a subclass, and Visual Studio 2013 either doesn't display the extra type detail that 2015 does, or you have it configured differently than I do.

like image 198
smelch Avatar answered Nov 08 '22 18:11

smelch