我目前正在使用FluentAssertion
比较2个对象。
我真的很想知道它用来比较的方式吗?
使用Reflection
然后像这样循环所有道具?
public static void PropertyValuesAreEquals(object actual, object expected) { PropertyInfo[] properties = expected.GetType().GetProperties(); foreach (PropertyInfo property in properties) { object expectedValue = property.GetValue(expected, null); object actualValue = property.GetValue(actual, null); if (!Equals(expectedValue, actualValue)) Assert.Fail("Property {0}.{1} does not match. Expected: {2} but was: {3}", property.DeclaringType.Name, property.Name, expectedValue, actualValue); //………………………………. }
如果使用其他方式进行比较,那是什么?
我目前正在使用FluentAssertion比较2个对象。我真的很想知道它用来比较的方式是什么?然后使用反射,然后像这样循环所有道具?公共静态无效...
我建议您read the documentation了解它使用的算法。但是我可以告诉你,它充满了反思。