SimilarValueComparer

Namespace: SnowBank.Runtime.Converters · class

Implements: IEqualityComparer<object>, IEqualityComparer, IComparer<object>, IComparer

Helper that compares instances for "similarity"

Remarks

This comparer SHOULD NOT be used in a Dictionary, because it violates on of the conditions: Some pairs of objects could be considered equal, but have different hashcode!

Properties

UsesRelaxedRules

bool UsesRelaxedRules { get; }

Gets a value that specifies whether the relaxed rules are used (true) or not (false)

Methods

Compare

int Compare(object x, object y)

Equals

bool Equals(object x, object y)

GetHashCode

int GetHashCode(object obj)

Fields

Default

static readonly SimilarValueComparer Default

Comparer that uses stricter rules when comparison objects for similarity.

In strict mode, double 123d is considered equal to the integer 123, but the string "123" is not.

All types of integers will be compared together, for example 123 == 123L == 123UL == 123.0 == 123m

All UUIDs of similar size will also be compared together, for example Guid and Uuid128.

When ordering values of different types that are not similar, they will be ordered according to their types, with the following ranking (from smaller to greater): null, bytes, strings, tuples, integers, decimals, booleans, guids, VersionStamps

Relaxed

static readonly SimilarValueComparer Relaxed

Comparer that uses relaxed rules when comparing objects for similarity.

This comparer adds more type conversions to the Default base.

For example, in relaxed mode, both the string "123" and double 123d are considered equal to integer 123, and false/true are equal to 0/1.