Repository navigation
OnixLabs.Core.None
Represents an absent optional value — the case of Optional<T> that holds no value.
| Namespace | OnixLabs.Core |
| Assembly | OnixLabs.Core.dll (NuGet) |
| Inheritance |
object → Optional<T> → None<T>
|
| Implements |
IValueEquatable<Optional<T>> (inherited from Optional<T>) |
public sealed class None<T> : Optional<T>
where T : notnull| Parameter | Description |
|---|---|
T |
The type of the underlying optional value. Constrained to notnull. |
None<T> is one of the two cases of Optional<T> and signifies that no value is present. Because Optional<T> is a closed class, a C# 15 switch over Some<T> and None<T> is exhaustive without a discard arm. It carries no data and exposes no public members of its own beyond those inherited from Optional<T>.
The constructor is private. A single shared instance is allocated per closed type T and is accessible through the static Optional<T>.None field. You should never need to reference None<T> by type directly — use the static field, the Of factory, or an implicit null conversion to obtain an absent optional.
None<T> inherits all members of Optional<T>. HasValue always returns false for a None<T>. GetValueOrThrow() throws InvalidOperationException. GetValueOrDefault() returns default(T). ToString() returns "None".
Use Optional<T>.IsNone(Optional<T>), HasValue, or a C# pattern match (is None<T>) to detect the absent case.
using OnixLabs.Core;
// Access the shared singleton.
Optional<int> none = Optional<int>.None;
Console.WriteLine(none.HasValue); // False
Console.WriteLine(none.ToString()); // None
// Implicit null conversion also yields None.
Optional<string> implicitNone = null;
Console.WriteLine(implicitNone.HasValue); // False
// Strip-default factory yields None for default values.
Optional<int> stripped = Optional<int>.Of(0);
Console.WriteLine(stripped.HasValue); // False
// Pattern match to detect absence.
Optional<string> optional = Optional<string>.None;
if (optional is None<string>)
{
Console.WriteLine("No value present.");
}
// GetValueOrDefault returns the specified fallback.
string result = Optional<string>.None.GetValueOrDefault("fallback"); // "fallback"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