Skip to content

Compare any objects based on their properties and property contents

License

Notifications You must be signed in to change notification settings

tobiaswuerth/Object-Content-Comparator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Object-Content-Comparator

Compare objects of any type based on their property values.

Download

✅ .net core v2.0
✅ .net framework v4.6
Download latest release here (pre-release v0.1)

How does it work?

The object is serialized into JSON (properties can be labled using the attributes [JsonProperty] and [JsonIgnore]) which then is hashed using the SHA512 Algorithm. The objects are compared by comparing their hashes which does not guarantee that every content generates a unique hash ... but pretty much. Click here to find out more.

Dependencies

Newtonsoft Json.NET Nuget package

Usage

var obj1 = new MyStatelessClass();
var obj2 = new MyStatelessClass();

Comparator.AreEqual(obj1, obj2);
>>> true

Comparator.AreEqual(15, "15"); // this is because string "15" and integer 15 are not considered equal
>>> false

Comparator.AreEqual(DateTime.MinValue, DateTime.Parse("01/01/0001 00:00:00"));
>>> true