Table of Contents

Class SecureComparerProvider

Namespace
Nerdbank.MessagePack
Assembly
Nerdbank.MessagePack.dll

An implementation of IComparerProvider that provides hash-collision resistant implementations of IEqualityComparer<T> generated by GetHashCollisionResistant<T>(ITypeShape<T>).

public class SecureComparerProvider : IComparerProvider
Inheritance
SecureComparerProvider
Implements
Inherited Members

Fields

Default

A singleton instance of the SecureComparerProvider.

public static readonly SecureComparerProvider Default

Field Value

SecureComparerProvider

Methods

GetComparer<T>(ITypeShape<T>)

Gets an IComparer<T> for a type described by a given ITypeShape<T>.

public virtual IComparer<T>? GetComparer<T>(ITypeShape<T> shape)

Parameters

shape ITypeShape<T>

The shape of the type to be compared.

Returns

IComparer<T>

An instance of IComparer<T> if the provider has or can construct one for the given type shape; otherwise null.

Type Parameters

T

The type of object to be compared.

Remarks

This implementation always returns null, since the security implications on comparers is (currently) limited to hash-based attacks, and IComparer<T> objects do not use hashing.

Derived types may override this method to return comparers where desired.

GetEqualityComparer<T>(ITypeShape<T>)

Gets an IEqualityComparer<T> for a type described by a given ITypeShape<T>.

public virtual IEqualityComparer<T>? GetEqualityComparer<T>(ITypeShape<T> shape)

Parameters

shape ITypeShape<T>

The shape of the type to be compared.

Returns

IEqualityComparer<T>

An instance of IEqualityComparer<T> if the provider has or can construct one for the given type shape; otherwise null.

Type Parameters

T

The type of object to be compared.

Remarks

This implementation returns the result of calling GetHashCollisionResistant<T>(ITypeShape<T>) with the given shape.

Derived types may override this method and return custom implementations of IEqualityComparer<T> for types for which the StructuralEqualityComparer-generated comparer is not sufficient, deferring to the base implementation for the rest.

See Also