Repository navigation
OnixLabs.Core.Success
Represents a successful, non-generic result.
| Namespace | OnixLabs.Core |
| Assembly | OnixLabs.Core.dll (NuGet) |
| Inheritance |
object → Result → Success
|
| Implements | IValueEquatable<Result> |
public sealed class Success : ResultSuccess has no public constructor; obtain the shared instance via Result.Success(). All successful non-generic results share a single singleton instance — there is nothing to distinguish one success from another, so allocating multiple instances would be wasteful.
Success is one of exactly two sealed derivations of Result. The other is Failure. Because Result is a closed class, a C# 15 switch over Success and Failure is exhaustive without a discard arm.
Success represents the outcome of an operation that completed without throwing an exception. Because it carries no payload, it is effectively a unit type: the only information it conveys is that the operation succeeded.
All Success instances compare equal to one another. Result.GetHashCode returns 0 for a Success, and Result.ToString returns string.Empty.
Success inherits the full combinator API — Select, SelectMany, Match, Throw, and their async variants — from Result. When the current instance is a Success, those combinators execute their delegate; when cast to Failure, they short-circuit. See the Result page for the complete inherited member list.
To promote an untyped Success to a typed Success<TResult>, use ToTypedResult<TResult>(TResult).
using OnixLabs.Core;
// Via the factory method (returns the singleton).
Success success = Result.Success();
// Via Result.Of — returns Success when the action does not throw.
Result result = Result.Of(() => File.Delete("/tmp/scratch.txt"));
Console.WriteLine(result.IsSuccess); // Trueusing OnixLabs.Core;
Success untyped = Result.Success();
Success<int> typed = untyped.ToTypedResult(42);
Console.WriteLine(typed.IsSuccess); // Trueusing OnixLabs.Core;
Result result = Result.Of(DoWork);
if (result is Success)
Console.WriteLine("Work completed successfully.");| Method | Returns | Description |
|---|---|---|
ToTypedResult<TResult>(TResult) |
Success<TResult> |
Promotes this success to a typed success carrying the specified value. |
public Success<TResult> ToTypedResult<TResult>(TResult value)Obtains a new Success<TResult> containing the specified value, promoting an untyped success to a typed one. This is the bridge from the non-generic result model to the generic Result<T> model.
| Parameter | Type | Description |
|---|---|---|
value |
TResult |
The underlying successful result value. |
Returns — A new Success<TResult> containing value.
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