CsCheck/Utils.cs
/// <summary>Default equal implementation. Handles most collections ordered for IList like or unordered for ICollection based.</summary>
Default equal implementation. Handles most collections ordered for IList like or unordered for ICollection based.
Default equal implementation . Handles most collections ordered for IList like or unordered for ICollection based .
public static bool Equal<T>(T a, T b)
        {
            if (a is IEquatable<T> aieq) return aieq.Equals(b);
            else if (a is Array aa2 && b is Array ba2 && aa2.Rank == 2)
            {
                int I = aa2.GetLength(0), J = aa2.GetLength(1);
                if (I != ba2.GetLength(0) || J != ba2.GetLength(1)) return false;
                for (int i = 0; i < I; i++)
                    for (int j = 0; j < J; j++)
                        if (!aa2.GetValue(i, j).Equals(ba2.GetValue(i, j)))
                            return false;
                return true;
            }
            else if (a is IList ail && b is IList bil)
            {
                if (ail.Count != bil.Count) return false;
                for (int i = 0; i < ail.Count; i++)
                    if (!ail[i].Equals(bil[i]))
                        return false;
                return true;
            }
            else if (a.GetType().GetInterface(typeof(IReadOnlyList<>).Name) != null)
            {
                var e1 = ((IEnumerable)a).GetEnumerator();
                var e2 = ((IEnumerable)b).GetEnumerator();
                while (true)
                {
                    var e1MoveNext = e1.MoveNext();
                    if (e1MoveNext != e2.MoveNext()) return false;
                    if (!e1MoveNext) return true;
                    if (!Equal(e1.Current, e2.Current)) return false;
                }
            }
            else if (a is ICollection aic && b is ICollection bic)
            {
                return aic.Count == bic.Count && !aic.Cast<object>().Except(bic.Cast<object>()).Any();
            }
            else if (a is IEnumerable aie && b is IEnumerable bie)
            {
                var aieo = aie.Cast<object>().ToList();
                var bieo = bie.Cast<object>().ToList();
                return aieo.Count == bieo.Count && !aieo.Except(bieo).Any();
            }
            return a.Equals(b);
        }
public static bool Equal < T > ( T a , T b ) { if ( a is IEquatable < T > aieq ) return aieq . Equals ( b ) ; else if ( a is Array aa2 && b is Array ba2 && aa2 . Rank == 2 ) { int I = aa2 . GetLength ( 0 ) , J = aa2 . GetLength ( 1 ) ; if ( I != ba2 . GetLength ( 0 ) || J != ba2 . GetLength ( 1 ) ) return false ; for ( int i = 0 ; i < I ; i ++ ) for ( int j = 0 ; j < J ; j ++ ) if ( ! aa2 . GetValue ( i , j ) . Equals ( ba2 . GetValue ( i , j ) ) ) return false ; return true ; } else if ( a is IList ail && b is IList bil ) { if ( ail . Count != bil . Count ) return false ; for ( int i = 0 ; i < ail . Count ; i ++ ) if ( ! ail [ i ] . Equals ( bil [ i ] ) ) return false ; return true ; } else if ( a . GetType ( ) . GetInterface ( typeof ( IReadOnlyList < > ) . Name ) != null ) { var e1 = ( ( IEnumerable ) a ) . GetEnumerator ( ) ; var e2 = ( ( IEnumerable ) b ) . GetEnumerator ( ) ; while ( true ) { var e1MoveNext = e1 . MoveNext ( ) ; if ( e1MoveNext != e2 . MoveNext ( ) ) return false ; if ( ! e1MoveNext ) return true ; if ( ! Equal ( e1 . Current , e2 . Current ) ) return false ; } } else if ( a is ICollection aic && b is ICollection bic ) { return aic . Count == bic . Count && ! aic . Cast < object > ( ) . Except ( bic . Cast < object > ( ) ) . Any ( ) ; } else if ( a is IEnumerable aie && b is IEnumerable bie ) { var aieo = aie . Cast < object > ( ) . ToList ( ) ; var bieo = bie . Cast < object > ( ) . ToList ( ) ; return aieo . Count == bieo . Count && ! aieo . Except ( bieo ) . Any ( ) ; } return a . Equals ( b ) ; }
Default equal implementation.
Default equal implementation .
a
T
b
T