Beispiel #1
0
        public static IComparer <Employee> SelectComparison(CompareWith option)
        {
            switch (option)
            {
            case CompareWith.FirstName:
                return(new EmployeeCompareWithFirstName());

            case CompareWith.LastName:
                return(new EmployeeCompareWithLastName());

            case CompareWith.Id:
                return(new EmployeeCompareWithID());
            }

            throw new System.InvalidOperationException();
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether two objects are equal.
        /// </summary>
        /// <param name="expected">The expected value.</param>
        /// <param name="actual">The actual value.</param>
        /// <returns></returns>
        private bool ObjectsEqual(object expected, object actual)
        {
            if (expected == null && actual == null)
            {
                return(true);
            }

            if (expected == null || actual == null)
            {
                return(false);
            }

            Type expectedType = expected.GetType();
            Type actualType   = actual.GetType();

            if (expectedType.IsArray && actualType.IsArray && !CompareAsCollection)
            {
                return(ArraysEqual((Array)expected, (Array)actual));
            }

            if (expected is ICollection && actual is ICollection)
            {
                return(CollectionsEqual((ICollection)expected, (ICollection)actual));
            }

            if (expected is Stream && actual is Stream)
            {
                return(StreamsEqual((Stream)expected, (Stream)actual));
            }

            if (CompareWith != null)
            {
                return(CompareWith.Compare(expected, actual) == 0);
            }

            if (Numerics.IsNumericType(expected) && Numerics.IsNumericType(actual))
            {
                return(Numerics.AreEqual(expected, actual, Tolerance));
            }

            if (expected is string && actual is string)
            {
                return(string.Compare((string)expected, (string)actual, CaseInsensitive, CultureInfo.CurrentCulture) == 0);
            }

            return(expected.Equals(actual));
        }