Skip to main content

Class Result

Namespace: OceanApocalypse.RSML.Toolchain.Abstractions.Diagnostics
Assembly: RSML.Toolchain.Abstractions.dll

A collection of factory methods for easier initialization of Result objects.

public static class Result

Inheritance

ObjectResult

Inherited Members

Object.Equals(Object?), Object.Equals(Object?, Object?), Object.GetHashCode(), Object.GetType(), Object.MemberwiseClone(), Object.ReferenceEquals(Object?, Object?), Object.ToString()

Methods

Failure(Diagnostic)

Returns a failure ("bad" result) for a boolean type.

public static Result<Boolean> Failure(Diagnostic error)

Parameters

error Diagnostic

The error.

Returns

Result<Boolean>

The failure, as a boolean result.

Failure<TValue>(Diagnostic)

Returns a failure ("bad" result) for a given type.

public static Result<TValue> Failure<TValue>(Diagnostic error)

Parameters

error Diagnostic

The error.

Returns

Result<TValue>

The failure.

Type Parameters

TValue

The type of value the result would normally contain.

FromException<TValue>(Exception?, String?)

Returns a failure ("bad" result) for a given type, given an Exception.

public static Result<TValue> FromException<TValue>(Exception? exception, String? errorCode)

Parameters

exception Exception?

The exception whose data to retrieve and use as failure data.

errorCode String?

A string error code for the failure. Leave null for a generic error code.

Returns

Result<TValue>

The failure.

Type Parameters

TValue

The type of value the result would normally contain.

FromNullable<TValue>(Object?, TValue)

Checks if a given object is null and, if it is, returns a failure. If the object is not null, returns a successful result with a given value.

public static Result<TValue> FromNullable<TValue>(Object? check, TValue value)

Parameters

check Object?

The object to check if null.

value TValue

The result value if check is not null.

Returns

Result<TValue>

Either a successful result or a failure.

Type Parameters

TValue

The type of value the result will contain if check is not null.

Success<TValue>(TValue)

Returns a successful result with a given value.

public static Result<TValue> Success<TValue>(TValue value)

Parameters

value TValue

The value.

Returns

Result<TValue>

The successful result.

Type Parameters

TValue

The type of value.

Success()

Returns a successful result with a true boolean.

public static Result<Boolean> Success()

Returns

Result<Boolean>

The successful result, with value set to true.

TryCatch<TValue, TException>(Func<TValue>)

Tries to run function check and return its output, unless it fails, in which case the returned result is also a failure.

public static Result<TValue> TryCatch<TValue, TException>(Func<TValue> check) where TException : Exception

Parameters

check Func<TValue>

The function to try and run.

Returns

Result<TValue>

Either a successful result, with the function's return value, or a failure.

Type Parameters

TValue

The type of value to return if successful

TException

The type of exception to check for. The check mode is not strict, polymorphism is checked.

Exceptions

ArgumentNullException

check is null.