Tns.DeepComparison
1.0.0
dotnet add package Tns.DeepComparison --version 1.0.0
NuGet\Install-Package Tns.DeepComparison -Version 1.0.0
<PackageReference Include="Tns.DeepComparison" Version="1.0.0" />
paket add Tns.DeepComparison --version 1.0.0
#r "nuget: Tns.DeepComparison, 1.0.0"
// Install Tns.DeepComparison as a Cake Addin
#addin nuget:?package=Tns.DeepComparison&version=1.0.0
// Install Tns.DeepComparison as a Cake Tool
#tool nuget:?package=Tns.DeepComparison&version=1.0.0
Deep Comparison of Objects
This is C# method which compares two objects - property by property; checks the values; It will inform any difference is found or not. It will traverse the object deeply up to n-th level and comprares primitive types, collections/enumrables, associated complex objects using recursion.
Accuracy
This comparer had been used regularly by a team of software engineers for more than a year. So many bugs are fixed in that time. After a period of time like 7/8 months, this method became stable (I hope!).
Use case
This method is written to prompt the user before closing a form without saving; when any change is found in the form.
Method definition
bool CompareObject(T obj1, T obj2, bool nullEqualsEmpty = true, int depth = -1, dynamic mismatchInfo = null)
Parameter description
- obj1 & obj2 (complex type): the objects that will be compared.
- nullEqualsEmpty (boolean): Whether null and empty values will be treated as equal or not. If true then those states will be treated as equal: null | empty | default | count 0 list.
- depth (int): How deep the compare method will go. -1 (or any negative): infinite level; 0 (zer0): only immediate, non-complex properties, >0 (any positive number): comparison will continue till the mentioned level.
- mismatchInfo (ExpandoObject): [For debugging purpose] Pass an empty ExpandoObject; information about mismatch will be included.
Returns (boolean): Whether the values of obj1 and obj2 are same or not.
Sample call
System.Dynamic.ExpandoObject mismatchInfo;
bool isIdentical = DeepComparison.CompareObject<Product>(currentProduct, oldProduct, nullEqualsEmpty: true, mismatchInfo: mismatchInfo);
if (!isIdentical)
{
MessageBox.Show("You have unsaved changes. Do you want to save your changes?", "Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.CSharp (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|