Beispiel #1
0
        public bool Equals(object[] x, object[] y)
        {
            if (ReferenceEquals(x, y))
            {
                return(true);
            }
            if (x.Length != y.Length)
            {
                return(false);
            }
            switch (x.Length)
            {
            case 1: return(eq(x[0], y[0]));

            case 2: return(eq(x[0], y[0]) && eq(x[1], y[1]));

            case 3: return(eq(x[0], y[0]) && eq(x[1], y[1]) && eq(x[2], y[2]));

            case 4: return(eq(x[0], y[0]) && eq(x[1], y[1]) && eq(x[2], y[2]) && eq(x[3], y[3]));

            default:
                for (int i = 0; i < x.Length; i++)
                {
                    if (!eq(x[i], y[i]))
                    {
                        return(false);
                    }
                }
                return(true);
            }

            bool eq(object a, object b)
            {
                var sameType = a.GetType() == b.GetType();

                if (sameType)
                {
                    // just Equals
                    return(a.Equals(b));
                }
                var sameHash = a.GetHashCode() == b.GetHashCode();

                if (sameHash)
                {
                    // this could be the same fixed-point value but different types
                    if (PivotDataHelper.IsConvertibleToDecimal(a.GetType()) &&
                        PivotDataHelper.IsConvertibleToDecimal(b.GetType()))
                    {
                        return(Convert.ToDecimal(a) == Convert.ToDecimal(b));
                    }
                }

                return(a.Equals(b));
            }
        }