How to ignore casing when using JTokenEqualityComparer?
JTokenEqualityComparer comp = new JTokenEqualityComparer();
// arrange
var obj1 = new JObject();
obj1.Add("First Name", "foo");
obj1.Add("Last Name", "bar");
var obj2 = new JObject();
obj2.Add("First Name", "Foo");
obj2.Add("Last Name", "Bar");
// act
var hashCode1 = comp.GetHashCode(obj1);
var hashCode2 = comp.GetHashCode(obj2);
// assert
Assert.Equal(hashCode1, hashCode2);
Update 1
I want to compare two JObjects. The objects may be deep complex object. JToken has static method DeepEquals
that compares two deep objects. However i want to get unique hash value and store that value in the SQL database. So sql procedures can also do comparison.
from SO
I did see that they have an internal method called GetDeepHashCode but the implementation is based on other protected properties and therefore, I cannot "copy" the code and create an extension method from it
and solution is
You can use JTokenEqualityComparer.GetHashCode(JToken token) for this purpose. It provides access to the GetDeepHashCode() method you saw.