Skip to content

[Deprecated] Deep comparison of objects. Look for differences of values of two objects.

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
LICENSE.txt
Notifications You must be signed in to change notification settings

TareqNewazShahriar/deep-comparison

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deep Comparison of Objects

[deprecated]

This is a .Net Nuget package to compare 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.

Test Nuget Package: DeepComparison

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!).

Method definition

bool CompareObject(T obj1, T obj2, bool treatNullAndEqualAsSame = true, int depth = -1, Type excludeType, dynamic mismatchInfo = null)

Parameter description

  • obj1 & obj2 (complex type): the objects that will be compared.

  • treatNullAndEqualAsSame (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.

  • excludeType (Type): Pass the Type of the object that you want to exclude from the comparison.

  • 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(currentProduct, oldProduct, nullEqualsEmpty: true, excludeType: typeof(ProductCategory), mismatchInfo: mismatchInfo);

if (!isIdentical)
{
  MessageBox.Show("You have unsaved changes. Do you want to save your changes?", "Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
}

About

[Deprecated] Deep comparison of objects. Look for differences of values of two objects.

Topics

Resources

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
LICENSE.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages