Table of Contents

SuccessfulValue<TResult> Class

Definition

Namespace
Cuemon
Assemblies
Cuemon.Kernel.dll
Source
src/Cuemon.Kernel/SuccessfulValue.cs

Provides a way to indicate a successful operation. This class cannot be inherited.

public sealed class SuccessfulValue<TResult> : ConditionalValue<TResult>

Type Parameters

TResult

The type of the return value of the operation.

Inheritance
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.

// Program.cs
using System;
using Cuemon;
using Contoso.Configuration;

SuccessfulValueOfTResultExample.Run();

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

Name Description
SuccessfulValue(TResult)

Initializes a new instance of the SuccessfulValue<TResult> class.

See Also

ConditionalValue<TResult>