CompareNETObjects
来自软件开发
简介
这个组件的主要功能如名字所示就是深入比较2个.NET对象,是否相等或者是否有差异。可能很多.NET对象实现了一些.NET自带的接口可以直接进行比较,但是这个组件比较的范围和功能更加广泛。例如:
可以比较默认的子节点;
可以比较结构体;
可以比较IList对象;
可以比较单维或者多维的数组对象;
可以比较枚举类型;
可以比较IDictionary对象;
可以比较数据集,数据表,字典等等;
可以比较私有字段或者属性等等。。。
还有很多,不一一列举,可以去官网详细了解。
官方网站:https://github.com/GregFinzer/Compare-Net-Objects
入门指南:https://github.com/GregFinzer/Compare-Net-Objects/wiki/Getting-Started
使用
Install-Package CompareNETObjects
示例代码:
//This is the comparison class CompareLogic compareLogic = new CompareLogic(); //Create a couple objects to compare Person person1 = new Person(); person1.DateCreated = DateTime.Now; person1.Name = "Greg"; Person person2 = new Person(); person2.Name = "John"; person2.DateCreated = person1.DateCreated; ComparisonResult result = compareLogic.Compare(person1, person2); //These will be different, write out the differences if (!result.AreEqual) Console.WriteLine(result.DifferencesString);