Class ReturnValue<T, E>
Represents an operation result that can contain either a value or an error object.
public class ReturnValue<T, E> where E : class
Type Parameters
TType of the returned value.
EType 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
valueTThe value produced by the operation.
ReturnValue(E)
Initializes an error ReturnValue<T, E> instance that carries an error object.
public ReturnValue(E error)
Parameters
errorEThe error produced by the operation.
Properties
Error
public E Error { get; }
Property Value
- E
IsError
Gets a value indicating whether the operation captured an error.
public bool IsError { get; }
Property Value
IsSuccess
Gets a value indicating whether the operation was successful.
public bool IsSuccess { get; }
Property Value
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
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
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
rvReturnValue<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
rvReturnValue<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
valueTThe value to wrap.
Returns
- ReturnValue<T, E>