Class JsonElementEqualityComparer
Compares two System.Text.Json.JsonElement instances for equality by using value-based comparison.
Inheritance
Implements
Inherited Members
Namespace: JsonCons.Utilities
Assembly: JsonCons.Utilities.dll
Syntax
public sealed class JsonElementEqualityComparer : IEqualityComparer<JsonElement>
Properties
| Improve this Doc View SourceInstance
Gets a singleton instance of JsonElementEqualityComparer. This property is read-only.
Declaration
public static JsonElementEqualityComparer Instance { get; }
Property Value
Type | Description |
---|---|
JsonElementEqualityComparer |
Methods
| Improve this Doc View SourceEquals(JsonElement, JsonElement)
Determines whether the provided System.Text.Json.JsonElement objects are equal.
If the two System.Text.Json.JsonElement instances have different data types, they are different.
If both System.Text.Json.JsonElement instances are null, true, or false, they are equal.
If both are strings, they are compared with the String.Equals method.
If both are numbers, and both can be represented by a System.Decimal, they are compared with the Decimal.Equals method, otherwise they are compared as doubles.
If both are objects, they are compared accoring to the following rules:
- If the two objects have a different number of properties, they are different.
- Otherwise, order each object's properties by name and compare sequentially. The properties are compared first by name with the String.Equals method, then by value with JsonElementEqualityComparer
- A mismatching property means the two System.Text.Json.JsonElement instance are different.
If both are arrays, and both have the same length and compare equal element wise with JsonElementEqualityComparer, they are equal, otherwise they are different.
Declaration
public bool Equals(JsonElement lhs, JsonElement rhs)
Parameters
Type | Name | Description |
---|---|---|
System.Text.Json.JsonElement | lhs | The first object of type cref="JsonElement"/> to compare. |
System.Text.Json.JsonElement | rhs | The second object of type cref="JsonElement"/> to compare. |
Returns
Type | Description |
---|---|
System.Boolean |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Unable to compare numbers as either System.Decimal or double (shouldn't happen.) |
GetHashCode(JsonElement)
Returns a hash code for the specified System.Text.Json.JsonElement value.
Declaration
public int GetHashCode(JsonElement value)
Parameters
Type | Name | Description |
---|---|---|
System.Text.Json.JsonElement | value |
Returns
Type | Description |
---|---|
System.Int32 | An Int32 value representing the hash code of the value. |