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
resultResult<TValue>The result to extract a value from.
defaultFactoryFunc<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
TValueThe type of the value in the Result.
Exceptions
- ArgumentNullException
Thrown when
defaultFactoryis 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
resultResult<TValue>The result to extract a value from.
defaultFactoryFunc<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
TValueThe type of the value in the Result.
Exceptions
- ArgumentNullException
Thrown when
defaultFactoryis 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
resultResult<TValue>The result to extract a value from.
defaultValueTValueThe value to return if the result is a failure.
Returns
- TValue
The success value, or
defaultValueon failure.
Type Parameters
TValueThe type of the value in the Result.