-
-
Notifications
You must be signed in to change notification settings - Fork 193
Documentation
GregFinzer edited this page Dec 19, 2017
·
8 revisions
There is a full help file. Get the code and see the Compare-Net-Objects-Help directory.. https://github.com/GregFinzer/Compare-Net-Objects/blob/master/Compare-NET-Objects-Help/Compare-NET-Objects-Help.chm?raw=true
Important
- By default for performance reasons, Compare .NET Objects only detects the first difference. To capture all differences set Config.MaxDifferences to the maximum differences desired.
- After the comparison, the differences are in the Differences list or in the DifferencesString properties.
- By default, a deep comparison is performed. To perform a shallow comparison, set CompareChildren = false
- By default, private properties and fields are not compared. Set Config.ComparePrivateProperties and Config.ComparePrivateFields to true to override this behavior.
- By default an exception is thrown when class types are different. To ignore object types, set Config.IgnoreObjectTypes to true
C# Example
//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);
VB.NET Example
'This is the comparison class
Dim compareLogic As New CompareLogic()
'Create a couple objects to compare
Dim person1 As New Person()
person1.DateCreated = Date.Now
person1.Name = "Greg"
Dim person2 As New Person()
person2.Name = "John"
person2.DateCreated = person1.DateCreated
Dim result As ComparisonResult = compareLogic.Compare(person1, person2)
These will be different, write out the differences
If not result.AreEqual Then
Console.WriteLine(result.DifferencesString)
End If
- .NET Framework 4.0 or Higher
- Portable Class Library for .NET 4.0+, Silverlight 5+, Windows Phone 8+, Windows 8+
- .NET Standard 1.3 or higher
- Visual Studio 2013 or Higher
- NUnit 2.4 or higher