/////////////////////////////////////////////////////////////////////// #region IComparer<IMutableAnyPair<T1,T2>> Members public int Compare( IMutableAnyPair <T1, T2> x, IMutableAnyPair <T1, T2> y ) { if ((x == null) && (y == null)) { return(0); } else if (x == null) { return(-1); } else if (y == null) { return(1); } else { int result = Comparer <T1> .Default.Compare(x.X, y.X); if (result != 0) { return(result); } return(Comparer <T2> .Default.Compare(x.Y, y.Y)); } }
/////////////////////////////////////////////////////////////////////// #region IComparable Members public int CompareTo( object obj ) { IMutableAnyPair <T1, T2> other = obj as IMutableAnyPair <T1, T2>; if (other == null) { throw new ArgumentException(); } return(CompareTo(other)); }
/////////////////////////////////////////////////////////////////////// #region System.Object Overrides public override bool Equals( object obj ) { IMutableAnyPair <T1, T2> pair = obj as IMutableAnyPair <T1, T2>; if (pair != null) { return(GenericOps <T1> .Equals(this.X, pair.X) && GenericOps <T2> .Equals(this.Y, pair.Y)); } else { return(false); } }
public static bool Extract( IMutableAnyPair <T1, T2> pair, ref T3 x, ref T4 y ) { try { // // HACK: This is not ideal; however, we cannot use the "as" // operator unless we place a restrictions on all the // types (i.e. they must be classes). // T3 x2 = (T3)(object)pair.X; /* throw */ T4 y2 = (T4)(object)pair.Y; /* throw */ // // NOTE: Assign to the variables provided by the caller now // that we know the casts were all successful. These // statements cannot throw. // x = x2; y = y2; // // NOTE: All of the casts succeeded. // return(true); } catch { // do nothing. } // // NOTE: One of the casts failed. // return(false); }
/////////////////////////////////////////////////////////////////////// #region IEquatable<IMutableAnyPair<T1,T2>> Members public bool Equals( IMutableAnyPair <T1, T2> other ) { return(CompareTo(other) == 0); }
/////////////////////////////////////////////////////////////////////// #region IComparable<IMutableAnyPair<T1,T2>> Members public int CompareTo( IMutableAnyPair <T1, T2> other ) { return(Compare(this, other)); }