This project is read-only.


Improve Equals Method and IEquatable<>


(This is a report of an issue posted by BigstickCarpet)
There are two Equals methods on the Azumuth struct; one for the generic Object.Equals implementation and one for the IEquatable<T> implementation. The IEquatable<T> implemenation calls the Object.Equals implemenation, but it passes the DecimalDegrees property value rather than the entire Azumuth struct. As a result, the Object.Equals method always returns false, since the parameter it receives is not an Azumuth instance.
One way to correct this is to change the IEquatable<T> method to pass the entire Azimuth struct to Object.Equals rather than just the DecimalDegrees property. Another option is to leave the IEquatable<T> method as-is and make the Object.Equals method smart enough to handle either value. For example, the Object.Equals method could be implemented as follows:
public override bool Equals(object obj)
// Convert objects to an Azimuth as needed before comparison
if (obj is Azimuth)
return Equals((Azimuth)obj);
// Compare degree value
return this.DecimalDegrees.Equals(obj);
Closed Aug 11, 2009 at 1:49 AM by BigstickCarpet


wrote Aug 11, 2009 at 1:49 AM

Resolved with changeset 39365.

wrote Feb 14, 2013 at 3:49 AM

wrote May 16, 2013 at 9:23 AM

wrote Dec 10, 2017 at 4:04 PM