Table of Contents

Class Result

Namespace
Dynamicweb.Core
Assembly
Dynamicweb.Core.dll

The Result class is used to return values from methods that can potentially fail with known exceptions. To adhere to the fail fast principle, use this pattern to indicate to clients the succes or failure of a given operation instead of using exceptions to control the program flow!

public class Result
Inheritance
Result
Derived
Inherited Members

Constructors

Result(bool, string)

Initializes a new instance of the Result class

protected Result(bool isSuccess, string error)

Parameters

isSuccess bool

A value indicating the success or failure of the operation

error string

An error message in case the operation failed

Exceptions

InvalidOperationException

Properties

Error

Gets the error message from a given operation in case the operation failed

public string Error { get; }

Property Value

string

IsFailure

Gets a value indicating the success or failure of a given operation

public bool IsFailure { get; }

Property Value

bool

IsSuccess

Gets a value indicating the success or failure of a given operation

public bool IsSuccess { get; }

Property Value

bool

Methods

Fail(string)

Returns a new failing result with the specified message

public static Result Fail(string message)

Parameters

message string

A message describing the reason an operation failed

Returns

Result

A failed Result

Fail<T>(string)

Returns a new Generic Result with the specified message

public static Result<T> Fail<T>(string message)

Parameters

message string

A message describing the reason an operation failed

Returns

Result<T>

A failed Result of type T

Type Parameters

T

Generic type T of the Result<T> class

Fail<T, TError>(TError)

Returns a new Generic Result with the specified Enum error type

public static Result<T, TError> Fail<T, TError>(TError errorType) where TError : struct

Parameters

errorType TError

An enum value indicating the reason for the failure

Returns

Result<T, TError>

Type Parameters

T

The Generic type T of the Result<T, TError> class

TError

The Generic type TError of the Result<T, TError> class where TError must be an Enum type

Ok()

Returns a new successful Result

public static Result Ok()

Returns

Result

Ok<T>(T)

Returns a new successful result with a value of type T

public static Result<T> Ok<T>(T value)

Parameters

value T

The value to return as part of the result

Returns

Result<T>

Type Parameters

T
To top