Given two instances of a class, is it a good and reliable practice to compare them by serializaing them first and then comparing byte arrays (or possibly hashes of arrays). These objects might have complex hierarchical properties 但是 (dàn shì) serialization should go as deep as required.
比较指的是确保原始类型的所有属性具有相等的值,复杂类型的属性具有原始类型的相等属性等等。至于集合属性,它们应该相互相等:具有相等元素,相同位置。
{ a , b , c } != { a , c , b }
{new Customer{Id=2, Name="abc"}, new Customer {Id=3, Name="def"}}
!=
{new Customer{Id=3, Name="def"}, new Customer {Id=2, Name="abc"}}
但是 (dàn shì)
{new Customer{Id=2, Name="abc"}, new Customer {Id=3, Name="def"}}
==
{new Customer{Id=2, Name="abc"}, new Customer {Id=3, Name="def"}}
我意思是指标准的.NET二进制格式化程序。
谢谢。