开发者

IEqualityComparer for class with many properties neither unique value

开发者 https://www.devze.com 2023-01-04 08:12 出处:网络
How do implementation for IEqualityComparer for this class? The ID property is not unique. Neit开发者_如何学编程her properties has unique values.

How do implementation for IEqualityComparer for this class?

The ID property is not unique. Neit开发者_如何学编程her properties has unique values.

The entity has 7 properties.

[Serializable()]
public class ServidorSeleccionadoDto
{
    [XmlAttribute()]
    public int Id { get; set; }

    [XmlAttribute()]
    public string Nombre { get; set; }

    [XmlAttribute()]
    public string IP { get; set; }

    [XmlAttribute()]
    public string Entorno { get; set; }

    [XmlAttribute()] // [XmlIgnore()]
    public string Habilitado { get; set; }

    [XmlAttribute()]
    public string Tipo { get; set; }

    [XmlAttribute()]
    public int IdGrupo { get; set; }
}


It looks like your object has an ID field. If this is unique to each object then you would only need to compare on that property.

public Boolean Equals(ServidorSeleccionadoDto obj)
{
   return this.ID == obj.ID;
}

Note: This would only work if ID is unique.


If the ID property is not unique you will need to compare all your objects properties.

public Boolean Equals(ServidorSeleccionadoDto obj)
{
    return this.ID == obj.ID && 
           this.Nombre.Equals(obj.Nombre) && 
           ... etc
}
0

精彩评论

暂无评论...
验证码 换一张
取 消