Struct NoneFailure
public struct NoneFailure : IResultFailure
- Implements
- Inherited Members
Examples
// NoneFailure is used when converting a None Maybe to a Result
Maybe<string> none = Maybe<string>.None;
Result<string> result = none.ToResult();
// result.IsFailure is true, and the failure type is NoneFailure
Properties
Type
The type of failure.
public Type Type { get; }
Property Value
Value
The singleton instance of NoneFailure.
public static NoneFailure Value { get; }
Property Value
Examples
Result<int> failure = Result<int>.FromFailure(NoneFailure.Value);
Methods
GetFailureMessage()
Returns the error message defined in the failure.
public string GetFailureMessage()
Returns
- string
The error message.
Examples
IResultFailure failure = ResultFailure.FromErrorMessage("Invalid input");
string message = failure.GetFailureMessage(); // "Invalid input"
ToException()
Converts the failure to an exception.
public Exception ToException()
Returns
- Exception
The exception.
Examples
IResultFailure failure = ResultFailure.FromErrorMessage("Operation failed");
throw failure.ToException();
ToResult<T>()
Converts the failure to a Result with a Failure state.
public Result<T> ToResult<T>()
Returns
- Result<T>
A Result with a Failure state.
Type Parameters
TThe underlying type of Result.
Examples
IResultFailure failure = ResultFailure.FromErrorMessage("Not found");
Result<User> result = failure.ToResult<User>();
Console.WriteLine(result.IsFailure); // true