Class SuccessfulValue<TResult>
- Namespace
- Cuemon
- Assembly
- Cuemon.Kernel.dll
Provides a way to indicate a successful operation. This class cannot be inherited.
public sealed class SuccessfulValue<TResult> : ConditionalValue<TResult>
Type Parameters
TResultThe type of the return value of the operation.
- Inheritance
-
ConditionalValue<TResult>SuccessfulValue<TResult>
- Inherited Members
Examples
The following example demonstrates how to use SuccessfulValue<TResult> to represent a typed operation that completed successfully, pairing a result value with a success signal.
using System;
using Cuemon;
namespace Contoso.Configuration;
public sealed class SuccessfulValueOfTResultExample
{
public static void Run()
{
ConditionalValue<int> outcome = ParsePort("443");
Console.WriteLine($"Succeeded: {outcome.Succeeded}");
Console.WriteLine($"Port: {outcome.Result}");
}
private static ConditionalValue<int> ParsePort(string text)
{
if (int.TryParse(text, out int port))
{
return new SuccessfulValue<int>(port);
}
return new UnsuccessfulValue<int>(new FormatException("The port number is invalid."));
}
}
Constructors
SuccessfulValue(TResult)
Initializes a new instance of the SuccessfulValue<TResult> class.
public SuccessfulValue(TResult result)
Parameters
resultTResultThe result.
See Also
ConditionalValue<TResult>