Table of Contents

Class ReturnValue<T, E>

Namespace
Utils.Objects
Assembly
Utils.dll

Represents an operation result that can contain either a value or an error object.

public class ReturnValue<T, E> where E : class

Type Parameters

T

Type of the returned value.

E

Type of the returned error.

Inheritance
ReturnValue<T, E>
Derived
Inherited Members
Extension Methods

Constructors

ReturnValue(T)

Initializes a successful ReturnValue<T, E> instance that carries a value.

public ReturnValue(T value)

Parameters

value T

The value produced by the operation.

ReturnValue(E)

Initializes an error ReturnValue<T, E> instance that carries an error object.

public ReturnValue(E error)

Parameters

error E

The error produced by the operation.

Properties

Error

Gets the error associated with the operation when IsError is true.

public E Error { get; }

Property Value

E

IsError

Gets a value indicating whether the operation captured an error.

public bool IsError { get; }

Property Value

bool

IsSuccess

Gets a value indicating whether the operation was successful.

public bool IsSuccess { get; }

Property Value

bool

Value

Gets the value returned by the operation.

public T Value { get; }

Property Value

T

Methods

Do(Action<T>, Action<E>)

Executes the appropriate callback depending on whether the instance represents success or failure.

public void Do(Action<T> onSuccess, Action<E> onError)

Parameters

onSuccess Action<T>

Callback executed when IsSuccess is true.

onError Action<E>

Callback executed when IsError is true.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

Operators

implicit operator T(ReturnValue<T, E>)

Extracts the value stored inside a ReturnValue<T, E>.

public static implicit operator T(ReturnValue<T, E> rv)

Parameters

rv ReturnValue<T, E>

The ReturnValue<T, E> to extract the value from.

Returns

T

The contained value.

implicit operator E(ReturnValue<T, E>)

Extracts the error stored inside a ReturnValue<T, E>.

public static implicit operator E(ReturnValue<T, E> rv)

Parameters

rv ReturnValue<T, E>

The ReturnValue<T, E> to extract the error from.

Returns

E

The contained error.

implicit operator ReturnValue<T, E>(T)

Creates a successful ReturnValue<T, E> from a value.

public static implicit operator ReturnValue<T, E>(T value)

Parameters

value T

The value to wrap.

Returns

ReturnValue<T, E>