Show / Hide Table of Contents

Class JsonElementEqualityComparer

Compares two System.Text.Json.JsonElement instances for equality by using value-based comparison.

Inheritance
System.Object
JsonElementEqualityComparer
Implements
System.Collections.Generic.IEqualityComparer<System.Text.Json.JsonElement>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: JsonCons.Utilities
Assembly: JsonCons.Utilities.dll
Syntax
public sealed class JsonElementEqualityComparer : IEqualityComparer<JsonElement>

Properties

| Improve this Doc View Source

Instance

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 Source

Equals(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.)

| Improve this Doc View Source

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.

Implements

System.Collections.Generic.IEqualityComparer<T>
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX