Table of Contents

Class Result

Namespace
Compendium.Core.Results
Assembly
Compendium.Core.dll

Represents the result of an operation that can either succeed or fail. Provides a functional approach to error handling without exceptions.

public class Result
Inheritance
Result
Derived
Result<TValue>
Inherited Members
Extension Methods

Constructors

Result(bool, Error)

Initializes a new instance of the Result class.

protected Result(bool isSuccess, Error error)

Parameters

isSuccess bool

A value indicating whether the operation was successful.

error Error

The error that occurred, if any.

Properties

Error

Gets the error that occurred during the operation.

public Error Error { get; }

Property Value

Error

IsFailure

Gets a value indicating whether the operation failed.

public bool IsFailure { get; }

Property Value

bool

IsSuccess

Gets a value indicating whether the operation was successful.

public bool IsSuccess { get; }

Property Value

bool

Methods

Combine(params Result[])

Combines multiple results into a single result.

public static Result Combine(params Result[] results)

Parameters

results Result[]

The results to combine.

Returns

Result

A successful result if all results are successful; otherwise, a failed result with the first error.

Combine(IEnumerable<Result>)

Combines multiple results into a single result.

public static Result Combine(IEnumerable<Result> results)

Parameters

results IEnumerable<Result>

The results to combine.

Returns

Result

A successful result if all results are successful; otherwise, a failed result with the first error.

Create(bool, Error)

Creates a result based on a condition.

public static Result Create(bool condition, Error error)

Parameters

condition bool

The condition to evaluate.

error Error

The error to use if the condition is false.

Returns

Result

A successful result if the condition is true; otherwise, a failed result.

Create<TValue>(TValue?, Error)

Creates a result based on a nullable value condition.

public static Result<TValue> Create<TValue>(TValue? value, Error error) where TValue : struct

Parameters

value TValue?

The nullable value.

error Error

The error to use if the value is null.

Returns

Result<TValue>

A successful result with the value if it has a value; otherwise, a failed result.

Type Parameters

TValue

The type of the value.

Create<TValue>(TValue?, Error)

Creates a result based on a value condition.

public static Result<TValue> Create<TValue>(TValue? value, Error error) where TValue : class

Parameters

value TValue

The value.

error Error

The error to use if the value is null.

Returns

Result<TValue>

A successful result with the value if it's not null; otherwise, a failed result.

Type Parameters

TValue

The type of the value.

Failure(Error)

Creates a failed result.

public static Result Failure(Error error)

Parameters

error Error

The error that occurred.

Returns

Result

A failed result.

Failure<TValue>(Error)

Creates a failed result with a value type.

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

Parameters

error Error

The error that occurred.

Returns

Result<TValue>

A failed result.

Type Parameters

TValue

The type of the value.

Success()

Creates a successful result.

public static Result Success()

Returns

Result

A successful result.

Success<TValue>(TValue)

Creates a successful result with a value.

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

Parameters

value TValue

The value.

Returns

Result<TValue>

A successful result with the specified value.

Type Parameters

TValue

The type of the value.

ToString()

Returns a string representation of the result.

public override string ToString()

Returns

string

A string that represents the current result.

Operators

implicit operator Result(Error)

Implicitly converts an Error to a Result.

public static implicit operator Result(Error error)

Parameters

error Error

The error.

Returns

Result