Beispiel #1
0
        public bool AreSimilar <T>(T first, T second)
        {
            var firstObjectProperties  = first.GetType().GetProperties();
            var secondObjectProperties = first.GetType().GetProperties();

            if (firstObjectProperties.Count() != secondObjectProperties.Count())
            {
                return(false);
            }

            for (int i = 0; i < firstObjectProperties.Count(); i++)
            {
                var typeOfObject = firstObjectProperties[i].PropertyType;

                if (!typeOfObject.IsNested)
                {
                    if (!ComparerManager.Comparer(typeOfObject).AreSimilar(firstObjectProperties[i].GetValue(first), secondObjectProperties[i].GetValue(second)))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!new ObjectComparer().AreSimilar(firstObjectProperties[i], secondObjectProperties[i]))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Beispiel #2
0
        public static bool AreSimilar <T>(T first, T second)
        {
            if (first == null && second == null)
            {
                return(true);
            }

            if (first == null || second == null)
            {
                return(false);
            }

            var typeOfObject = first.GetType();

            var typeOfComparer = ComparerManager.Comparer(typeOfObject);

            if (!typeOfComparer.AreSimilar(first, second))
            {
                return(false);
            }

            return(true);
        }