Repository navigation
OnixLabs.Core.Collections.Generic.IEqualityComparerExtensions
Provides extension methods for IEqualityComparer<T> instances, supplying a convenience extension over a possibly-null comparer.
| Namespace | OnixLabs.Core.Collections.Generic |
| Assembly | OnixLabs.Core.dll (NuGet) |
| Inheritance |
object → IEqualityComparerExtensions
|
[EditorBrowsable(EditorBrowsableState.Never)]
public static class IEqualityComparerExtensionsNote
IEqualityComparerExtensionsis marked[EditorBrowsable(EditorBrowsableState.Never)], so it is hidden from IntelliSense completion lists even though it ispublic. Its extension methodGetOrDefaultis still fully usable on anyIEqualityComparer<T>?receiver after addingusing OnixLabs.Core.Collections.Generic;.
The extension operates over an IEqualityComparer<T>? receiver, which may be null. It is used throughout the LINQ extensions in OnixLabs.Core.Linq to normalise an optional comparer argument: callers may pass null to mean "use the default comparer for the element type", and GetOrDefault resolves that to a concrete, non-null comparer.
The class uses a C# 14 extension block (extension<T>(IEqualityComparer<T>? receiver) { ... }), so the receiver type appears in the block declaration rather than as a this parameter. The call-site signature is the standard extension-method form shown below.
using OnixLabs.Core.Collections.Generic;
using System.Collections.Generic;
IEqualityComparer<string>? maybeComparer = null;
// Resolves to EqualityComparer<string>.Default when null.
IEqualityComparer<string> comparer = maybeComparer.GetOrDefault();
bool equal = comparer.Equals("a", "a"); // Trueusing OnixLabs.Core.Collections.Generic;
using System.Collections.Generic;
static bool ContainsItem<T>(IEnumerable<T> source, T item, IEqualityComparer<T>? comparer = null)
{
IEqualityComparer<T> resolved = comparer.GetOrDefault();
foreach (T element in source)
if (resolved.Equals(element, item)) return true;
return false;
}| Method | Returns | Description |
|---|---|---|
GetOrDefault<T>() |
IEqualityComparer<T> |
Gets the current comparer, or the default comparer when it is null. |
public IEqualityComparer<T> GetOrDefault()Gets the current IEqualityComparer<T>, or the default comparer (EqualityComparer<T>.Default) if the current comparer is null.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the current IEqualityComparer<T> instance. |
Returns — The current IEqualityComparer<T>, or EqualityComparer<T>.Default if the current comparer is null.
ONIXLabs .NET Library · Repository · NuGet · License (Apache-2.0)
Copyright © ONIXLabs 2020. Licensed under the Apache License, Version 2.0.
- Enumeration<T>
- Optional<T>
- OptionalEqualityComparer<T>
- OptionalExtensions
- Result
- Result<T>
- ResultEqualityComparer<T>
- ResultExtensions
- Specification<T>
- Preconditions
- IValueEquatable<T>
- IValueComparable<T>
- IBinaryConvertible
- ISpanBinaryConvertible
- IMemoryBinaryConvertible
- ArrayExtensions
- ComparableExtensions
- DateTimeExtensions
- ISpanParsableExtensions
- ObjectExtensions
- RandomExtensions
- ReadOnlySequenceExtensions
- ReadOnlySpanExtensions
- StringExtensions
- Base16
- Base32
- Base58
- Base64
- IBaseCodec
- IBaseValue
- IBaseValue<T>
- Base16Codec
- Base32Codec
- Base58Codec
- Base64Codec
- Base16FormatProvider
- Base32FormatProvider
- Base58FormatProvider
- Base64FormatProvider
- EncodingExtensions
- ReadOnlySpanExtensions
- StringBuilderExtensions
- BigDecimal
- BigDecimalEqualityComparer
- BigDecimalOrdinalityComparer
- NumberInfo
- NumberInfoEqualityComparer
- NumberInfoOrdinalityComparer
- Int256
- Int512
- UInt256
- UInt512
- Float128
- Float256
- GenericMath
- NumericsExtensions
- ConversionMode
- ScaleMode
- Hash
- NamedHash
- Sha3
- Sha3Hash224
- Sha3Hash256
- Sha3Hash384
- Sha3Hash512
- Sha3Shake128
- Sha3Shake256
- MerkleTree
- MerkleTree<T>
- PrivateKey
- PublicKey
- NamedPrivateKey
- NamedPublicKey
- EcdhPrivateKey
- EcdhPublicKey
- EcdsaPrivateKey
- EcdsaPublicKey
- EddsaPrivateKey
- EddsaPublicKey
- RsaPrivateKey
- RsaPublicKey
- DigitalSignature
- DigitalSignatureAndPublicKey
- Salt
- Secret
- ICryptoPrimitive<T>
- IHashable
- IEcdhPrivateKey
- IEcdsaPrivateKey
- IEddsaPrivateKey
- IRsaPrivateKey
- IPrivateKeyDerivable<T>
- IPrivateKeyExportable
- IPrivateKeyImportable<T>
- IPrivateKeyPemImportable<T>
- IPrivateKeyPkcs8Exportable
- IPrivateKeyPkcs8Importable<T>
- IPrivateKeyPkcs8PemExportable
- IPrivateKeyRawExportable
- IPrivateKeyRawImportable<T>
- IPrivateKeyRawPemExportable
- IEcdhPublicKey
- IEcdsaPublicKey
- IEddsaPublicKey
- IRsaPublicKey
- IPublicKeyExportable
- IPublicKeyImportable<T>
- IPublicKeyPemExportable
- IPublicKeyPemImportable<T>
- IPublicKeyRawExportable
- IPublicKeyRawImportable<T>
- HashAlgorithmExtensions
- ReadOnlySpanExtensions