I'm trying to implement IEqueatable so I could use .Except in my custom type LINQ queries.
The custom type code looks like this:
public class Case : IEquatable<Case>
{
[Key]
public int Id { get; set; }
//More properties
[...]
public bool Equals(Case other)
{
// Check whether the compared object references the same data.
if (ReferenceEquals(this, other)) return true;
// Check whether the compared object is null.
if (ReferenceEquals(other, null)) return false;
// Check whether the objects’ properties are equal.
return Id.Equals(other.Id);
}
public override bool Equals(object obj)
{
var other = obj as Case;
// Check whether the compared object references the same data.
if (ReferenceEquals(this, other)) return true;
// Check whether the compared object is null.
if (ReferenceEquals(other, null)) return false;
// Check whether the objects’ properties are equal.
return Id.Equals(other.Id);
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
public static bool operator ==(Case case1, Case case2)
{
if ((object)case1 == null || (object)case2 == null)
return Equals(case1, case2);
return case1.Equals(case2);
}
public static bool operator !=(Case case1, Case case2)
{
if ((object)case1 == null || (object)case2 == null)
return !Equals(case1, case2);
return !case1.Equals(case2);
}
}
I've added throw new NotImplementedException();
in the Equals method but it never gets called.
I've followed the conventions shown here: https://msdn.microsoft.com/en-us/library/ms131190.aspx
But no success.
EDIT
Here's the code that calls for the Except method:
if (Checkset(set))
{
var subset = GetPowerSet(set);
var newset = powerset.Except(subset);
}
Where both powerset
and subset
are array of Case
.