Table of Contents

Struct Result<TValue>

Namespace
GreenDonut
Assembly
GreenDonut.dll

A wrapper for a single value which could contain a valid value or any error.

public readonly struct Result<TValue> : IEquatable<Result<TValue>>

Type Parameters

TValue

A value type.

Implements
Inherited Members

Constructors

Result(Exception)

Creates a new error result.

public Result(Exception error)

Parameters

error Exception

The error.

Result(TValue)

Creates a new value result.

public Result(TValue value)

Parameters

value TValue

The value.

Properties

Error

Gets an error If Kind is Error; otherwise null.

public Exception? Error { get; }

Property Value

Exception

Kind

Gets a value indicating whether the result is an error, a value or undefined.

public ResultKind Kind { get; }

Property Value

ResultKind

Value

Gets the value. If Kind is Error, returns null or default depending on its type.

public TValue Value { get; }

Property Value

TValue

Methods

Equals(Result<TValue>)

public bool Equals(Result<TValue> other)

Parameters

other Result<TValue>

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

Reject(Exception)

Creates a new error result.

public static Result<TValue> Reject(Exception error)

Parameters

error Exception

An arbitrary error.

Returns

Result<TValue>

An error result.

Resolve(TValue)

Creates a new value result.

public static Result<TValue> Resolve(TValue value)

Parameters

value TValue

An arbitrary value.

Returns

Result<TValue>

A value result.

Operators

implicit operator Exception?(Result<TValue>)

Extracts the error from a result.

public static implicit operator Exception?(Result<TValue> result)

Parameters

result Result<TValue>

An arbitrary result.

Returns

Exception

implicit operator TValue(Result<TValue>)

Extracts the value from a result.

public static implicit operator TValue(Result<TValue> result)

Parameters

result Result<TValue>

An arbitrary result.

Returns

TValue

implicit operator Result<TValue>(Exception?)

Creates a new error result or a null result.

public static implicit operator Result<TValue>(Exception? error)

Parameters

error Exception

An arbitrary error.

Returns

Result<TValue>

implicit operator Result<TValue>(TValue)

Creates a new value result.

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

Parameters

value TValue

An arbitrary value.

Returns

Result<TValue>