Hello, Implement IEquatable on generics classes has 2 bugs:
- Does not work at all on generic classes without the ancestor :
C#public class ValueNameItemTest<T>
{
public ValueNameItemTest(T value, string name)
{
Value = value;
Name = name;
}
public T Value { get; set; }
public string Name { get; set; }
}
- On generic classes with ancestor generates methods without type parameter:
C#public class ValueNameItemTest<T> : object
{
public ValueNameItemTest(T value, string name)
{
Value = value;
Name = name;
}
public T Value { get; set; }
public string Name { get; set; }
}
get expanded to:
C#public class ValueNameItemTest<T> : object, IEquatable<ValueNameItemTest>
{
public ValueNameItemTest(T value, string name)
{
Value = value;
Name = name;
}
public T Value { get; set; }
public string Name { get; set; }
public override bool Equals(object obj)
{
if (obj is ValueNameItemTest)
{
return Equals((ValueNameItemTest)obj);
}
return base.Equals(obj);
}
public static bool operator ==(ValueNameItemTest first, ValueNameItemTest second)
{
if ((object)first == null)
{
return (object)second == null;
}
return first.Equals(second);
}
public static bool operator !=(ValueNameItemTest first, ValueNameItemTest second)
{
return !(first == second);
}
public bool Equals(ValueNameItemTest other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Equals(Value, other.Value) && Equals(Name, other.Name);
}
public override int GetHashCode()
{
unchecked
{
int hashCode = 47;
if (Value != null)
{
hashCode = (hashCode * 53) ^ EqualityComparer<T>.Default.GetHashCode(Value);
}
if (Name != null)
{
hashCode = (hashCode * 53) ^ EqualityComparer<string>.Default.GetHashCode(Name);
}
return hashCode;
}
}
}
Hi Karel,
Thank you for the report. I reproduced this issue. You will get notified when we fix it. Please bear with us.