DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.4.0" />

.NET API 473,608 bytes

 Result<T, TError>

public struct Result<T, TError> : IResultMonad<T, TError, Result<T, TError>>, IResultMonad<T, TError>, IOptionMonad<T>, ISupplier<object>, IOptionMonad<T, Result<T, TError>> where TError : struct, Enum
Represents a result of operation which can be actual result or error code.
public TError Error { get; }

Gets the error code.

public bool IsSuccessful { get; }

Indicates that the result is successful.

public T Value { get; }

Extracts the actual result.

public Result(T value)

Initializes a new successful result.

public Result(TError error)

Initializes a new unsuccessful result.

public static bool op_BitwiseAnd(ref Result left, ref Result right)

Indicates that both results are successful.

public static T op_Explicit(ref Result result)

Extracts actual result.

public static bool op_False(ref Result result)

Indicates that the result represents error.

public static Optional<T> op_Implicit(ref Result result)

Converts the result into Optional<T>.

public static Result<T> op_Implicit(ref Result result)

Converts the result into Result<T>.

public static Result<T, TError> op_Implicit(T result)

Converts value into the result.

public static bool op_True(ref Result result)

Indicates that the result is successful.

public Result<object, TError> Box()

Gets boxed representation of the result.

public Result<TResult, TError> Convert<TResult>(Converter<T, TResult> converter)

If successful result is present, apply the provided mapping function hiding any exception caused by the converter.

public Result<TResult, TError> Convert<TResult>(method converter)

public T Or(T defaultValue)

Returns the value if present; otherwise return default value.

public T OrDefault()

Returns the value if present; otherwise return default value.

public T OrInvoke(Func<T> defaultFunc)

Returns the value if present; otherwise invoke delegate.

public T OrInvoke(method defaultFunc)

public T OrInvoke(Func<TError, T> defaultFunc)

Returns the value if present; otherwise invoke delegate.

public T OrInvoke(method defaultFunc)

public T OrThrow(Func<TError, Exception> exceptionFactory)

Gets underlying value or throws an exception.

public T OrThrow(method exceptionFactory)

public Result<T> ToResult()

Converts this result into Result<T>.

public bool TryGet(out T value)

Attempts to extract value from container if it is present.

public Optional<T> TryGet()

Converts the result into Optional<T>.