Table of Contents

Class GetValueOrDefaultExtensions

Namespace
Trellis
Assembly
Trellis.Results.dll

Terminal extraction methods for Result values.

public static class GetValueOrDefaultExtensions
Inheritance
GetValueOrDefaultExtensions
Inherited Members

Methods

GetValueOrDefault<TValue>(Result<TValue>, Func<Error, TValue>)

Returns the success value, or evaluates the factory (which receives the error) to produce a default. The factory is only invoked on the failure track. This is a terminal operator that exits the Result railway.

public static TValue GetValueOrDefault<TValue>(this Result<TValue> result, Func<Error, TValue> defaultFactory)

Parameters

result Result<TValue>

The result to extract a value from.

defaultFactory Func<Error, TValue>

A factory function that receives the error and produces a default value.

Returns

TValue

The success value, or the factory result on failure.

Type Parameters

TValue

The type of the value in the Result.

Exceptions

ArgumentNullException

Thrown when defaultFactory is null.

GetValueOrDefault<TValue>(Result<TValue>, Func<TValue>)

Returns the success value, or evaluates the factory to produce a default if the result is a failure. The factory is only invoked on the failure track. This is a terminal operator that exits the Result railway.

public static TValue GetValueOrDefault<TValue>(this Result<TValue> result, Func<TValue> defaultFactory)

Parameters

result Result<TValue>

The result to extract a value from.

defaultFactory Func<TValue>

A factory function invoked only when the result is a failure.

Returns

TValue

The success value, or the factory result on failure.

Type Parameters

TValue

The type of the value in the Result.

Exceptions

ArgumentNullException

Thrown when defaultFactory is null.

GetValueOrDefault<TValue>(Result<TValue>, TValue)

Returns the success value, or the specified default if the result is a failure. This is a terminal operator that exits the Result railway.

public static TValue GetValueOrDefault<TValue>(this Result<TValue> result, TValue defaultValue)

Parameters

result Result<TValue>

The result to extract a value from.

defaultValue TValue

The value to return if the result is a failure.

Returns

TValue

The success value, or defaultValue on failure.

Type Parameters

TValue

The type of the value in the Result.