internal static bool EqualsStatic(T x, T y) { if (IsIEquatable) { return(Unsafe.EqualsConstrained(ref x, ref y)); } return(EqualityComparer <T> .Default.Equals(x, y)); }
public void CouldUseCompareAndEqualsMethods() { var v1 = new CompEq(1); var v2 = new CompEq(2); var v3 = new CompEq(2); Assert.AreEqual(-1, Unsafe.CompareToConstrained(ref v1, ref v2)); Assert.AreEqual(1, Unsafe.CompareToConstrained(ref v2, ref v1)); Assert.AreEqual(0, Unsafe.CompareToConstrained(ref v2, ref v3)); Assert.AreEqual(1, Unsafe.CompareToConstrained(ref v3, ref v1)); Assert.True(Unsafe.EqualsConstrained(ref v2, ref v3)); Assert.False(Unsafe.EqualsConstrained(ref v1, ref v3)); }