Test.BudgetModelTest.PropertiesEqual C# (CSharp) Méthode

PropertiesEqual() public méthode

public PropertiesEqual ( object object1, object object2 ) : bool
object1 object
object2 object
Résultat bool
        public bool PropertiesEqual(object object1, object object2)
        {
            Type sourceType = object1.GetType();
            Type destinationType = object2.GetType();

            PropertyInfo[] sourceProperties = sourceType.GetProperties();
            foreach (PropertyInfo pi in sourceProperties)
            {
                if (!(sourceType.GetProperty(pi.Name).GetValue(object1, null).ToString() == destinationType.GetProperty(pi.Name).GetValue(object2, null).ToString()))
                {
                    // only need one property to be different to fail Equals.
                    return false;
                }
            }
            return true;
        }