Show / Hide Table of Contents

Struct Result<T>

Represents the result of an operation that can succeed or fail.

Implements
IEquatable<Result<T>>
IComparable<Result<T>>
Inherited Members
System.ValueType.ToString()
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: MediatorForge.Results
Assembly: MediatorForge.dll
Syntax
public readonly struct Result<T>
Type Parameters
Name Description
T

The type of the value.

Constructors

| Improve this Doc View Source

Result(T)

Initializes a new instance of the Result<T> struct with a successful value.

Declaration
public Result(T value)
Parameters
Type Name Description
T value

The value of the successful result.

| Improve this Doc View Source

Result(Exception)

Initializes a new instance of the Result<T> struct with a failure exception.

Declaration
public Result(Exception error)
Parameters
Type Name Description
Exception error

The exception of the failed result.

Properties

| Improve this Doc View Source

Exception

Gets the exception of the result if it is a failure.

Declaration
public readonly Exception? Exception { get; }
Property Value
Type Description
System.Nullable<Exception>
| Improve this Doc View Source

IsSuccess

Gets a value indicating whether the result is successful.

Declaration
public readonly bool IsSuccess { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

Value

Gets the value of the result if it is successful.

Declaration
public readonly T Value { get; }
Property Value
Type Description
T

Methods

| Improve this Doc View Source

CompareTo(Result<T>)

Compares this instance with another Result<T> and returns an integer that indicates whether this instance precedes, follows, or occurs in the same position in the sort order as the other Result<T>.

Declaration
public readonly int CompareTo(Result<T> other)
Parameters
Type Name Description
Result<T> other

A Result<T> to compare with this instance.

Returns
Type Description
System.Int32

A value that indicates the relative order of the objects being compared.

| Improve this Doc View Source

Equals(Result<T>)

Determines whether this instance and another specified Result<T> have the same value or exception.

Declaration
public readonly bool Equals(Result<T> other)
Parameters
Type Name Description
Result<T> other

The Result<T> to compare to this instance.

Returns
Type Description
System.Boolean

true if the value or exception of the specified Result<T> is equal to the value or exception of this instance; otherwise, false.

| Improve this Doc View Source

Equals(Object)

Determines whether the specified object is equal to this instance.

Declaration
public override readonly bool Equals(object obj)
Parameters
Type Name Description
System.Object obj

The object to compare with this instance.

Returns
Type Description
System.Boolean

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

Overrides
System.ValueType.Equals(System.Object)
| Improve this Doc View Source

Fail(Exception)

Creates a failed result.

Declaration
public static Result<T> Fail(Exception error)
Parameters
Type Name Description
Exception error

The exception of the failed result.

Returns
Type Description
Result<T>

A failed Result<T>.

| Improve this Doc View Source

GetHashCode()

Returns the hash code for this instance.

Declaration
public override readonly int GetHashCode()
Returns
Type Description
System.Int32

A hash code for the current object.

Overrides
System.ValueType.GetHashCode()
| Improve this Doc View Source

Match(Action<T>, Action<Exception>)

Executes one of the specified functions based on whether the result is successful or failed.

Declaration
public readonly void Match(Action<T> onSuccess, Action<Exception> onFailure)
Parameters
Type Name Description
Action<T> onSuccess

The function to execute if the result is successful.

Action<Exception> onFailure

The function to execute if the result is failed.

| Improve this Doc View Source

Match<TResult>(Func<T, TResult>, Func<Exception, TResult>)

Executes one of the specified functions based on whether the result is successful or failed.

Declaration
public readonly TResult Match<TResult>(Func<T, TResult> onSuccess, Func<Exception, TResult> onFailure)
Parameters
Type Name Description
Func<T, TResult> onSuccess

The function to execute if the result is successful.

Func<Exception, TResult> onFailure

The function to execute if the result is failed.

Returns
Type Description
TResult

The result of the executed function.

Type Parameters
Name Description
TResult

The type of the result produced by the functions.

| Improve this Doc View Source

OnFailure(Action<Exception>)

Executes the specified action if the result is failed.

Declaration
public readonly void OnFailure(Action<Exception> onFailure)
Parameters
Type Name Description
Action<Exception> onFailure

The action to execute if the result is failed.

| Improve this Doc View Source

OnSuccess(Action<T>)

Executes the specified action if the result is successful.

Declaration
public readonly void OnSuccess(Action<T> onSuccess)
Parameters
Type Name Description
Action<T> onSuccess

The action to execute if the result is successful.

| Improve this Doc View Source

Succ(T)

Creates a successful result.

Declaration
public static Result<T> Succ(T value)
Parameters
Type Name Description
T value

The value of the successful result.

Returns
Type Description
Result<T>

A successful Result<T>.

Operators

| Improve this Doc View Source

Equality(Result<T>, Result<T>)

Determines whether two Result<T> instances are equal.

Declaration
public static bool operator ==(Result<T> left, Result<T> right)
Parameters
Type Name Description
Result<T> left

The first Result<T> to compare.

Result<T> right

The second Result<T> to compare.

Returns
Type Description
System.Boolean

true if the two Result<T> instances are equal; otherwise, false.

| Improve this Doc View Source

GreaterThan(Result<T>, Result<T>)

Determines whether one Result<T> instance follows another in the sort order.

Declaration
public static bool operator>(Result<T> left, Result<T> right)
Parameters
Type Name Description
Result<T> left

The first Result<T> to compare.

Result<T> right

The second Result<T> to compare.

Returns
Type Description
System.Boolean

true if the first Result<T> follows the second in the sort order; otherwise, false.

| Improve this Doc View Source

GreaterThanOrEqual(Result<T>, Result<T>)

Determines whether one Result<T> instance follows or is equal to another in the sort order.

Declaration
public static bool operator >=(Result<T> left, Result<T> right)
Parameters
Type Name Description
Result<T> left

The first Result<T> to compare.

Result<T> right

The second Result<T> to compare.

Returns
Type Description
System.Boolean

true if the first Result<T> follows or is equal to the second in the sort order; otherwise, false.

| Improve this Doc View Source

Implicit(T to Result<T>)

Implicitly converts a value to a successful Result<T> containing that value.

Declaration
public static implicit operator Result<T>(T value)
Parameters
Type Name Description
T value

The value to convert.

Returns
Type Description
Result<T>
| Improve this Doc View Source

Implicit(Exception to Result<T>)

Implicitly converts an exception to a failed Result<T> containing that exception.

Declaration
public static implicit operator Result<T>(Exception error)
Parameters
Type Name Description
Exception error

The exception to convert.

Returns
Type Description
Result<T>
| Improve this Doc View Source

Inequality(Result<T>, Result<T>)

Determines whether two Result<T> instances are not equal.

Declaration
public static bool operator !=(Result<T> left, Result<T> right)
Parameters
Type Name Description
Result<T> left

The first Result<T> to compare.

Result<T> right

The second Result<T> to compare.

Returns
Type Description
System.Boolean

true if the two Result<T> instances are not equal; otherwise, false.

| Improve this Doc View Source

LessThan(Result<T>, Result<T>)

Determines whether one Result<T> instance precedes another in the sort order.

Declaration
public static bool operator <(Result<T> left, Result<T> right)
Parameters
Type Name Description
Result<T> left

The first Result<T> to compare.

Result<T> right

The second Result<T> to compare.

Returns
Type Description
System.Boolean

true if the first Result<T> precedes the second in the sort order; otherwise, false.

| Improve this Doc View Source

LessThanOrEqual(Result<T>, Result<T>)

Determines whether one Result<T> instance precedes or is equal to another in the sort order.

Declaration
public static bool operator <=(Result<T> left, Result<T> right)
Parameters
Type Name Description
Result<T> left

The first Result<T> to compare.

Result<T> right

The second Result<T> to compare.

Returns
Type Description
System.Boolean

true if the first Result<T> precedes or is equal to the second in the sort order; otherwise, false.

Implements

IEquatable<>
IComparable<>
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX