f0f1f2.studio Template reference
English
Open application

CreateComparer

Definition

Namespace
Resto.Front.PrintTemplates.Cheques.Razor

IEqualityComparer<TObject> TemplateBase<T>.CreateComparer<TObject>(Func<TObject, TObject, bool> equals)

Definition

Namespace
Resto.Front.PrintTemplates.Cheques.Razor

Creates an equality comparer backed by an equality delegate and a constant hash code.

IEqualityComparer<TObject> TemplateBase<T>.CreateComparer<TObject>(Func<TObject, TObject, bool> equals)
Returns
IEqualityComparer<TObject>
Nullability
Not specified
Declared in
Resto.Front.PrintTemplates.Cheques.Razor.TemplateBase<T>
Model purpose
Base class for Legacy Razor print templates. Model contains the document data of type T. Provides formatting and markup output methods.

Parameters

Func<TObject, TObject, bool> equals
Equality function; must not be null. Receives the original operands, including null for reference types.

Type parameters

TObject
Type of objects to compare.

Return value

A new IEqualityComparer<TObject> that forwards calls to the supplied delegates.

Remarks

GetHashCode always returns 0, so the equality/hash contract is satisfied but hash collections can degrade to linear searches. For large Distinct, GroupBy or dictionary workloads, prefer the overload with a compatible hash function. Exceptions from equals propagate when comparison is performed.

Exceptions

System.ArgumentNullException
equals is null.

Example

var comparer = CreateComparer<string>(StringComparer.OrdinalIgnoreCase.Equals);
comparer.Equals("Tea", "TEA"); // true
comparer.GetHashCode("Tea"); // 0

Type arguments

TObject
No description is provided for this symbol.

IEqualityComparer<TObject> TemplateBase<T>.CreateComparer<TObject>(Func<TObject, TObject, bool> equals, Func<TObject, int> getHashCode)

Definition

Namespace
Resto.Front.PrintTemplates.Cheques.Razor

Creates an equality comparer backed by equality and hash-code delegates.

IEqualityComparer<TObject> TemplateBase<T>.CreateComparer<TObject>(Func<TObject, TObject, bool> equals, Func<TObject, int> getHashCode)
Returns
IEqualityComparer<TObject>
Nullability
Not specified
Declared in
Resto.Front.PrintTemplates.Cheques.Razor.TemplateBase<T>
Model purpose
Base class for Legacy Razor print templates. Model contains the document data of type T. Provides formatting and markup output methods.

Parameters

Func<TObject, TObject, bool> equals
Equality function; must not be null. Receives the original operands, including null for reference types.
Func<TObject, int> getHashCode
Hash-code function; must not be null and must return the same hash for equal objects.

Type parameters

TObject
Type of objects to compare.

Return value

A new IEqualityComparer<TObject> that forwards calls to the supplied delegates.

Remarks

Equality must be reflexive, symmetric and transitive, and compatible with the hash function. Delegates must handle null if callers can pass it. Delegate exceptions propagate when the comparer is used, not when it is created.

Exceptions

System.ArgumentNullException
equals or getHashCode is null.

Example

var comparer = CreateComparer<string>(StringComparer.OrdinalIgnoreCase.Equals,
    s => s == null ? 0 : StringComparer.OrdinalIgnoreCase.GetHashCode(s));
comparer.Equals("Tea", "TEA"); // true

Type arguments

TObject
No description is provided for this symbol.