Bug Report T413999
Visible to All Users

Implement IEquatable doesn't work on CodeRush Roslyn

created 9 years ago

Seems like the 'Implement IEquatable' refactoring in CodeRush for Roslyn doesn't work.  In an example class I have it generates this:

C#
public class FacilityCfg : IEquatable<FacilityCfg> { public string FacId { get; set; } public int DataVer { get; set; } public int DelFlg { get; set; } public string OrderCdFmt { get; set; } public string AllowAbsOrder { get; set; } public string AllowBookingOrder { get; set; } public FacilityCfg() { FacId = ""; OrderCdFmt = ""; AllowAbsOrder = "N"; AllowBookingOrder = "N"; } public override string ToString() { return string.Format("{0} (DataVer:{2}{3})", FacId, DataVer, DelFlg == 1 ? "DELETED" : ""); } public override bool Equals(object obj) { if (obj is FacilityCfg) return Equals((FacilityCfg)obj); return base.Equals(obj); } public static bool operator ==(FacilityCfg first, FacilityCfg second) { if ((object)first == null) return (object)second == null; return first.Equals(second); } public static bool operator !=(FacilityCfg first, FacilityCfg second) { return !(first == second); } public bool Equals(FacilityCfg other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return false; } public override int GetHashCode() { unchecked { var hashCode = 47; return hashCode; } } } }

However, classing CodeRush generated this:

C#
public override bool Equals(object obj) { if (obj is FacilityCfg) return Equals((FacilityCfg)obj); return base.Equals(obj); } public static bool operator ==(FacilityCfg first, FacilityCfg second) { if ((object)first == null) return (object)second == null; return first.Equals(second); } public static bool operator !=(FacilityCfg first, FacilityCfg second) { return !(first == second); } public bool Equals(FacilityCfg other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(this.FacId, other.FacId) && this.DataVer.Equals(other.DataVer) && this.DelFlg.Equals(other.DelFlg) && Equals(this.OrderCdFmt, other.OrderCdFmt) && Equals(this.AllowAbsOrder, other.AllowAbsOrder) && Equals(this.AllowBookingOrder, other.AllowBookingOrder); } public override int GetHashCode() { unchecked { int hashCode = 47; if (this.FacId != null) hashCode = (hashCode * 53) ^ this.FacId.GetHashCode(); hashCode = (hashCode * 53) ^ this.DataVer.GetHashCode(); hashCode = (hashCode * 53) ^ this.DelFlg.GetHashCode(); if (this.OrderCdFmt != null) hashCode = (hashCode * 53) ^ this.OrderCdFmt.GetHashCode(); if (this.AllowAbsOrder != null) hashCode = (hashCode * 53) ^ this.AllowAbsOrder.GetHashCode(); if (this.AllowBookingOrder != null) hashCode = (hashCode * 53) ^ this.AllowBookingOrder.GetHashCode(); return hashCode; } }

Seems like a problem to me - by maybe I've got something configured wrong?  I have latest versions of both Editions of CodeRush.

Comments (1)
DevExpress Support Team 9 years ago

    Hi Nicholas,
    Thank you for code snippets.
    I have reproduced the problem for the following source class.

    C#
    namespace NamespaceName { public class FacilityCfg { public string FacId { get; set; } public int DataVer { get; set; } public int DelFlg { get; set; } public string OrderCdFmt { get; set; } public string AllowAbsOrder { get; set; } public string AllowBookingOrder { get; set; } public FacilityCfg() { FacId = ""; OrderCdFmt = ""; AllowAbsOrder = "N"; AllowBookingOrder = "N"; } public override string ToString() { return string.Format("{0} (DataVer:{2}{3})", FacId, DataVer, DelFlg == 1 ? "DELETED" : ""); } } }

    We will try to fix it as soon as possible. Once we make any progress, we will let you know.

    Answers approved by DevExpress Support

    created 9 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.