Bug Report T663890
Visible to All Users

Refactorings - The "Implement IEquatable" refactoring on generic classes works incorrectly

created 7 years ago (modified 7 years ago)

Hello, Implement IEquatable on generics classes has 2 bugs:

  1. 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; } }
  1. 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; } } }
Comments (1)
PW PW
Przemyslaw Wlodarczak (DevExpress) 7 years ago

    Hi Karel,

    Thank you for the report. I reproduced this issue. You will get notified when we fix it. Please bear with us.

    Answers approved by DevExpress Support

    created 7 years ago

    We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

    Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.