documentation.dxp
0
on
on
FSI.Lib.Compare-NET-Objects
<DIV class=wikidoc><A href="http://www.FSI.Lib.com"><IMG style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none" title="Kellerman Software Logo" alt="Kellerman Software Logo" src="http://www.FSI.Lib.com/images/logo.gif"></A><BR><BR><B>Project Description</B><BR>What you have been waiting for. Perform a deep compare of any two .NET objects using reflection. Shows the differences between the two objects. <BR><BR><B>NuGet Package</B><BR><A href="http://www.nuget.org/packages/CompareNETObjects"><FONT color=#0066cc>http://www.nuget.org/packages/CompareNETObjects</FONT></A><BR><BR>Features <UL> <LI>Compare Primitive Types <LI>Compare Structs <LI>Compare IList Objects <LI>Compare Single and Multi-Dimensional Arrays <LI>Compare IDictionary Objects <LI>Compare Publicly visible Class Fields and Properties <LI>Compare Children <LI>Handling for Trees with Children Pointing To Parents <LI>Compare Enums <LI>Compare Timespans <LI>Compare Guids <LI>Compare Classes that Implement IList with Indexers <LI>Compare DataSet Data <LI>Compare DataTable Data <LI>Compare DataRow Data <LI>Compare LinearGradient <LI>Compare HashSet <LI>Compare URI <LI>Compare Types of Type (RuntimeType) <LI>Source code in both C# and in VB.NET <LI>NUnit Test Project Included <LI>Ability to load settings from a config file for use with powershell <LI>Several configuration options for comparing private elements, and ignoring specific elements. <LI>Property and Field Info reflection caching for increased performance</LI></UL></DIV>
<P class=wikidoc><STRONG>Important</STRONG></P> <DIV class=wikidoc> <UL> <LI>By default for performance reasons, Compare .NET Objects only detects the first difference.&nbsp; To capture all differences set MaxDifferences to the maximum differences desired. <LI>After the comparison, the differences are in the Differences list or in the DifferencesString properties. <LI>By default, a deep comparison is performed.&nbsp; To perform a shallow comparison, set CompareChildren = false <LI>By default, private properties and fields are not compared.&nbsp; Set ComparePrivateProperties and ComparePrivateFields to true to override this behavior. </LI></UL></DIV> <P>&nbsp;</P> <P><STRONG>C# Example</STRONG></P> <DIV style="BACKGROUND-COLOR: white; COLOR: black"><PRE><SPAN style="COLOR: green">//This is the comparison class</SPAN> CompareObjects compareObjects = <SPAN style="COLOR: blue">new</SPAN> CompareObjects();

<SPAN style="COLOR: green">//Create a couple objects to compare</SPAN> Person person1 = <SPAN style="COLOR: blue">new</SPAN> Person(); person1.DateCreated = DateTime.Now; person1.Name = <SPAN style="COLOR: #a31515">"Greg"</SPAN>;

Person person2 = <SPAN style="COLOR: blue">new</SPAN> Person(); person2.Name = <SPAN style="COLOR: #a31515">"John"</SPAN>; person2.DateCreated = person1.DateCreated;

<SPAN style="COLOR: green">//These will be different, write out the differences</SPAN> <SPAN style="COLOR: blue">if</SPAN> (!compareObjects.Compare(person1, person2)) Console.WriteLine(compareObjects.DifferencesString); </PRE></DIV> <P><STRONG></STRONG>&nbsp;</P> <P>&nbsp;</P> <P><STRONG>VB.NET Example</STRONG></P> <DIV style="BACKGROUND-COLOR: white; COLOR: black"><PRE><SPAN style="COLOR: green">'This is the comparison class</SPAN> <SPAN style="COLOR: blue">Dim</SPAN> compareObjects <SPAN style="COLOR: blue">As</SPAN> <SPAN style="COLOR: blue">New</SPAN> CompareObjects()

<SPAN style="COLOR: green">'Create a couple objects to compare</SPAN> <SPAN style="COLOR: blue">Dim</SPAN> person1 <SPAN style="COLOR: blue">As</SPAN> <SPAN style="COLOR: blue">New</SPAN> Person()<BR>person1.DateCreated = <SPAN style="COLOR: blue">Date</SPAN>.Now person1.Name = <SPAN style="COLOR: #a31515">"Greg"</SPAN>

<SPAN style="COLOR: blue">Dim</SPAN> person2 <SPAN style="COLOR: blue">As</SPAN> <SPAN style="COLOR: blue">New</SPAN> Person() person2.Name = <SPAN style="COLOR: #a31515">"John"</SPAN> person2.DateCreated = person1.DateCreated

<SPAN style="COLOR: green">'These will be different, write out the differences</SPAN> <SPAN style="COLOR: blue">If</SPAN> <SPAN style="COLOR: blue">Not</SPAN> compareObjects.Compare(person1, person2) <SPAN style="COLOR: blue">Then</SPAN> Console.WriteLine(compareObjects.DifferencesString) <SPAN style="COLOR: blue">End</SPAN> <SPAN style="COLOR: blue">If</SPAN> </PRE></DIV>
Compare .NET Objects
true
true
true
true
false
false
false
true