Table of Contents

Struct Result<T>

Namespace
Olve.Results
Assembly
Olve.Results.dll

Represents a result of an operation with a value, indicating success or failure.

public readonly struct Result<T>

Type Parameters

T

The type of the result value.

Inherited Members
Extension Methods

Properties

Failed

Gets a value indicating whether the operation failed.

public bool Failed { get; }

Property Value

bool

Problems

Gets the collection of problems associated with the result, if any.

public ResultProblemCollection? Problems { get; }

Property Value

ResultProblemCollection

Succeeded

Gets a value indicating whether the operation succeeded.

public bool Succeeded { get; }

Property Value

bool

Value

Gets the value associated with the result, if any.

public T? Value { get; }

Property Value

T

Methods

Failure(params IEnumerable<ResultProblem>)

Creates a result representing failure with the specified problems.

[Obsolete("Use Result.Failure<T> instead")]
public static Result<T> Failure(params IEnumerable<ResultProblem> problems)

Parameters

problems IEnumerable<ResultProblem>

The problems associated with the failure.

Returns

Result<T>

A failure result.

GetValueOrDefault(T)

Gets the value of the result or throws an exception if the result is a failure.

public T GetValueOrDefault(T defaultValue)

Parameters

defaultValue T

The default value to return if the result is a failure.

Returns

T

The value of the result or the default value.

IfProblem(Action<ResultProblemCollection>)

Executes a sequence of functions that return a Result<T>.

public Result<T> IfProblem(Action<ResultProblemCollection> action)

Parameters

action Action<ResultProblemCollection>

The function to execute.

Returns

Result<T>

The result of the function.

Success(T)

Creates a result representing success with the specified value.

public static Result<T> Success(T value)

Parameters

value T

The value associated with the success.

Returns

Result<T>

A success result.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

TryGetValueOrDefault(out T?, T)

Attempts to retrieve the value of the result or a default value.

public bool TryGetValueOrDefault(out T? value, T defaultValue)

Parameters

value T

The value of the result or the default value.

defaultValue T

The default value to return if the result is a failure.

Returns

bool

true if a value exists; otherwise, false.

TryPickProblems(out ResultProblemCollection?)

Attempts to retrieve the problems associated with the result.

public bool TryPickProblems(out ResultProblemCollection? problems)

Parameters

problems ResultProblemCollection

When this method returns true, contains the problems. Otherwise, null.

Returns

bool

true if problems exist; otherwise, false.

TryPickProblems(out ResultProblemCollection?, out T?)

Attempts to retrieve the problems associated with the result.

public bool TryPickProblems(out ResultProblemCollection? problems, out T? value)

Parameters

problems ResultProblemCollection

When this method returns true, contains the problems. Otherwise, null.

value T

When this method returns false, contains the value. Otherwise, null.

Returns

bool

true if problems exist; otherwise, false.

TryPickValue(out T?)

Attempts to retrieve the value of the result.

public bool TryPickValue(out T? value)

Parameters

value T

When this method returns true, contains the value. Otherwise, null.

Returns

bool

true if a value exists; otherwise, false.

TryPickValue(out T?, out ResultProblemCollection?)

Attempts to retrieve the value of the result.

public bool TryPickValue(out T? value, out ResultProblemCollection? problems)

Parameters

value T

When this method returns true, contains the value. Otherwise, null.

problems ResultProblemCollection

When this method returns false, contains the problems. Otherwise, null.

Returns

bool

true if a value exists; otherwise, false.

Operators

implicit operator Result<T>(ResultProblem)

Converts the specified problem to a failure result.

public static implicit operator Result<T>(ResultProblem problem)

Parameters

problem ResultProblem

The problem to convert.

Returns

Result<T>

A failure result.

implicit operator Result<T>(ResultProblemCollection)

Converts the specified problems to a failure result.

public static implicit operator Result<T>(ResultProblemCollection problems)

Parameters

problems ResultProblemCollection

The problems to convert.

Returns

Result<T>

A failure result.

implicit operator Result<T>(T)

Converts the specified value to a success result.

public static implicit operator Result<T>(T value)

Parameters

value T

The value to convert.

Returns

Result<T>

A success result.