Bug Report T464602
Visible to All Users

Implement IEquatable for structures shouldn't test for nullability or reference equality

created 8 years ago

Given:

C#
public struct MyStruct { public MyStruct(string name) { this.Name = name; } public string Name { get; } }

The implementation should not generate code like:

C#
public static bool operator ==(MyStruct first, MyStruct second) { if ((object)first == null) return (object)second == null; return first.Equals(second); } public bool Equals(ExitPointTarget other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(this.Name, other.Name); }

The correct implementation should be:

C#
public static bool operator ==(MyStruct first, MyStruct second) { return first.Equals(second); } public bool Equals(ExitPointTarget other) { return Equals(this.Name, other.Name); }
Comments (1)
DevExpress Support Team 8 years ago

    Hello Paulo,

    Thank you for pointing out this issue and providing a code sample.
    We agree with you that we shouldn't do nullability or reference equality checks for structures.

    We will change this behavior and notify you as soon as we do this.

    Answers approved by DevExpress Support

    created 8 years ago (modified 8 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.

      Comments (2)

        The fix is versioned 16.2.3.16356, not 16.2.4.

        But it works!

        DevExpress Support Team 8 years ago

          Hello Paulo,

          Thank you for letting us know about your results.
          You are right, the fix version is 16.2.3.16356.
          CodeRush for Roslyn v16.2.4 will be released in a few weeks, and will include the fix for this issue as well.

          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.