Struct Result
- Namespace
- LightResults
- Assembly
- LightResults.dll
Represents a result.
public readonly struct Result : IEquatable<Result>, IActionableResult<Result>, IResultImplements
Inherited Members
Properties
Errors
Gets a read-only collection of errors associated with the result.
public IReadOnlyCollection<IError> Errors { get; }Property Value
Methods
AsFailure()
Converts the current LightResults.Result`1 to a failure LightResults.Result.
public Result AsFailure()Returns
- Result
- 
A new instance of LightResults.Result containing the same error as the LightResults.Result`1, if any. 
AsFailure<TDestination>()
Converts the current LightResults.Result`1 to a failure LightResults.Result`1.
public Result<TDestination> AsFailure<TDestination>()Returns
- Result<TDestination>
- 
A new instance of LightResults.Result`1 containing the same error as the LightResults.Result`1, if any. 
Type Parameters
- TDestination
- 
The type of the value of the failure result. 
Equals(in Result)
Determines whether two LightResults.Result instances are equal.
public bool Equals(in Result other)Parameters
- otherResult
- 
The LightResults.Result instance to compare with this instance. 
Returns
- bool
- 
trueif the specified LightResults.Result is equal to this instance; otherwise,false.
Equals(object?)
Determines whether the specified object is equal to this instance.
public override bool Equals(object? obj)Parameters
- objobject?
- 
The object to compare with this instance. 
Returns
- bool
- 
trueif the specified object is equal to this instance; otherwise,false.
Failure()
Creates a failure result.
public static Result Failure()Returns
- Result
- 
A new instance of LightResults.Result representing a failure result. 
Failure(string)
Creates a failure result with the given error message.
public static Result Failure(string errorMessage)Parameters
- errorMessagestring
- 
The error message associated with the failure. 
Returns
- Result
- 
A new instance of LightResults.Result representing a failure result with the specified error message. 
Failure(string, (string Key, object? Value))
Creates a failure result with the given error message and metadata.
public static Result Failure(string errorMessage, (string Key, object? Value) metadata)Parameters
- errorMessagestring
- 
The error message associated with the failure. 
- metadata(string Key, object? Value)
- 
The metadata associated with the failure. 
Returns
- Result
- 
A new instance of LightResults.Result representing a failure result with the specified error message and metadata. 
Failure(string, KeyValuePair<string, object?>)
Creates a failure result with the given error message and metadata.
public static Result Failure(string errorMessage, KeyValuePair<string, object?> metadata)Parameters
- errorMessagestring
- 
The error message associated with the failure. 
- metadataKeyValuePair<string, object?>
- 
The metadata associated with the failure. 
Returns
- Result
- 
A new instance of LightResults.Result representing a failure result with the specified error message and metadata. 
Failure(string, IReadOnlyDictionary<string, object?>)
Creates a failure result with the given error message and metadata.
public static Result Failure(string errorMessage, IReadOnlyDictionary<string, object?> metadata)Parameters
- errorMessagestring
- 
The error message associated with the failure. 
- metadataIReadOnlyDictionary<string, object?>
- 
The metadata associated with the failure. 
Returns
- Result
- 
A new instance of LightResults.Result representing a failure result with the specified error message and metadata. 
Failure(Exception?)
Creates a failure result with the given exception.
public static Result Failure(Exception? ex)Parameters
- exException?
- 
The System.Exception associated with the failure, if any. 
Returns
- Result
- 
A new instance of LightResults.Result representing a failure result with the specified exception. 
Remarks
The exception is added to the error LightResults.Error.Metadata under the key of "Exception" and the error LightResults.Error.Message is set to that of the exception.
Failure(string, Exception?)
Creates a failure result with the given error message and exception.
public static Result Failure(string errorMessage, Exception? ex)Parameters
- errorMessagestring
- 
The error message associated with the failure. 
- exException?
- 
The System.Exception associated with the failure, if any. 
Returns
- Result
- 
A new instance of LightResults.Result representing a failure result with the specified error message and exception. 
Remarks
The exception is added to the error LightResults.Error.Metadata under the key of "Exception".
Failure(IError)
Creates a failure result with the given error.
public static Result Failure(IError error)Parameters
- errorIError
- 
The error associated with the failure. 
Returns
- Result
- 
A new instance of LightResults.Result representing a failure result with the specified error. 
Failure(IEnumerable<IError>)
Creates a failure result with the given errors.
public static Result Failure(IEnumerable<IError> errors)Parameters
- errorsIEnumerable<IError>
- 
A collection of errors associated with the failure. 
Returns
- Result
- 
A new instance of LightResults.Result representing a failure result with the specified errors. 
Failure(IReadOnlyList<IError>)
Creates a failure result with the given errors.
public static Result Failure(IReadOnlyList<IError> errors)Parameters
- errorsIReadOnlyList<IError>
- 
A collection of errors associated with the failure. 
Returns
- Result
- 
A new instance of LightResults.Result representing a failure result with the specified errors. 
Failure<TValue>()
Creates a failure result.
public static Result<TValue> Failure<TValue>()Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a failure result. 
Type Parameters
- TValue
- 
The type of the value of the result. 
Failure<TValue>(string)
Creates a failure result with the given error message.
public static Result<TValue> Failure<TValue>(string errorMessage)Parameters
- errorMessagestring
- 
The error message associated with the failure. 
Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a failure result with the specified error message. 
Type Parameters
- TValue
- 
The type of the value of the result. 
Failure<TValue>(string, (string Key, object? Value))
Creates a failure result with the given error message and metadata.
public static Result<TValue> Failure<TValue>(string errorMessage, (string Key, object? Value) metadata)Parameters
- errorMessagestring
- 
The error message associated with the failure. 
- metadata(string Key, object? Value)
- 
The metadata associated with the failure. 
Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a failure result with the specified error message and metadata. 
Type Parameters
- TValue
- 
The type of the value of the result. 
Failure<TValue>(string, KeyValuePair<string, object?>)
Creates a failure result with the given error message and metadata.
public static Result<TValue> Failure<TValue>(string errorMessage, KeyValuePair<string, object?> metadata)Parameters
- errorMessagestring
- 
The error message associated with the failure. 
- metadataKeyValuePair<string, object?>
- 
The metadata associated with the failure. 
Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a failure result with the specified error message and metadata. 
Type Parameters
- TValue
- 
The type of the value of the result. 
Failure<TValue>(string, IReadOnlyDictionary<string, object?>)
Creates a failure result with the given error message and metadata.
public static Result<TValue> Failure<TValue>(string errorMessage, IReadOnlyDictionary<string, object?> metadata)Parameters
- errorMessagestring
- 
The error message associated with the failure. 
- metadataIReadOnlyDictionary<string, object?>
- 
The metadata associated with the failure. 
Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a failure result with the specified error message and metadata. 
Type Parameters
- TValue
- 
The type of the value of the result. 
Failure<TValue>(Exception?)
Creates a failure result with the given exception.
public static Result<TValue> Failure<TValue>(Exception? ex)Parameters
- exException?
- 
The System.Exception associated with the failure, if any. 
Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a failure result with the specified exception. 
Type Parameters
- TValue
Remarks
The exception is added to the error LightResults.Error.Metadata under the key of "Exception" and the error LightResults.Error.Message is set to that of the exception.
Failure<TValue>(string, Exception?)
Creates a failure result with the given error message and exception.
public static Result<TValue> Failure<TValue>(string errorMessage, Exception? ex)Parameters
- errorMessagestring
- 
The error message associated with the failure. 
- exException?
- 
The System.Exception associated with the failure, if any. 
Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a failure result with the specified error message and exception. 
Type Parameters
- TValue
Remarks
The exception is added to the error LightResults.Error.Metadata under the key of "Exception".
Failure<TValue>(IError)
Creates a failure result with the given error.
public static Result<TValue> Failure<TValue>(IError error)Parameters
- errorIError
- 
The error associated with the failure. 
Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a failure result with the specified error. 
Type Parameters
- TValue
- 
The type of the value of the result. 
Failure<TValue>(IEnumerable<IError>)
Creates a failure result with the given errors.
public static Result<TValue> Failure<TValue>(IEnumerable<IError> errors)Parameters
- errorsIEnumerable<IError>
- 
A collection of errors associated with the failure. 
Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a failure result with the specified errors. 
Type Parameters
- TValue
- 
The type of the value of the result. 
Failure<TValue>(IReadOnlyList<IError>)
Creates a failure result with the given errors.
public static Result<TValue> Failure<TValue>(IReadOnlyList<IError> errors)Parameters
- errorsIReadOnlyList<IError>
- 
A collection of errors associated with the failure. 
Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a failure result with the specified errors. 
Type Parameters
- TValue
- 
The type of the value of the result. 
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()Returns
- int
- 
A 32-bit signed integer hash code. 
HasError<TError>()
Checks if the result contains an error of the specified type.
public bool HasError<TError>() where TError : IErrorReturns
- bool
- 
trueif an error of the specified type exists; otherwise,false.
Type Parameters
- TError
- 
The type of error to check for. 
HasError<TError>(out TError)
Checks if the result contains an error of the specified type.
public bool HasError<TError>(out TError error) where TError : IErrorParameters
- errorTError
- 
The error of the specified type. 
Returns
- bool
- 
trueif an error of the specified type exists; otherwise,false.
Type Parameters
- TError
- 
The type of error to check for. 
IsFailure()
Determines whether the result is a failure.
public bool IsFailure()Returns
- bool
- 
trueif the result is a failure; otherwise,false.
IsFailure(out IError)
Determines whether the result is a failure.
public bool IsFailure(out IError error)Parameters
- errorIError
- 
The error of the result. 
Returns
- bool
- 
trueif the result is a failure; otherwise,false.
IsSuccess()
Determines whether the result was successful.
public bool IsSuccess()Returns
- bool
- 
trueif the result was successful; otherwise,false.
Success()
Creates a success result.
public static Result Success()Returns
- Result
- 
A new instance of LightResults.Result representing a success result. 
Success<TValue>(TValue)
Creates a success result with the specified value.
public static Result<TValue> Success<TValue>(TValue value)Parameters
- valueTValue
- 
The value to include in the result. 
Returns
- Result<TValue>
- 
A new instance of LightResults.Result`1 representing a success result with the specified value. 
Type Parameters
- TValue
- 
The type of the value of the result. 
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()Returns
- string
- 
The fully qualified type name. 
Operators
operator ==(in Result, in Result)
Determines whether two LightResults.Result instances are equal.
public static bool operator ==(in Result left, in Result right)Parameters
- leftResult
- 
The first LightResults.Result instance to compare. 
- rightResult
- 
The second LightResults.Result instance to compare. 
Returns
- bool
- 
trueif the specified LightResults.Result instances are equal; otherwise,false.
implicit operator Result(Error)
Implicitly converts an LightResults.Error to a failure LightResults.Result`1.
public static implicit operator Result(Error error)Parameters
- errorError
- 
The error to convert into a failure result. 
Returns
- Result
- 
A new instance of LightResults.Result`1 representing a failure result with the specified error. 
operator !=(in Result, in Result)
Determines whether two LightResults.Result instances are not equal.
public static bool operator !=(in Result left, in Result right)Parameters
- leftResult
- 
The first LightResults.Result instance to compare. 
- rightResult
- 
The second LightResults.Result instance to compare. 
Returns
- bool
- 
trueif the specified LightResults.Result instances are not equal; otherwise,false.