Struct Result
- Namespace
- LightResults
- Assembly
- LightResults.dll
Represents a result.
public readonly struct Result : IEquatable<Result>, IActionableResult<Result>, IResult
Implements
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(Result)
Determines whether two LightResults.Result instances are equal.
public bool Equals(Result other)
Parameters
other
Result-
The LightResults.Result instance to compare with this instance.
Returns
- bool
-
true
if 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
obj
object?-
The object to compare with this instance.
Returns
- bool
-
true
if 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
errorMessage
string-
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
errorMessage
string-
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
errorMessage
string-
The error message associated with the failure.
metadata
KeyValuePair<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
errorMessage
string-
The error message associated with the failure.
metadata
IReadOnlyDictionary<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
ex
Exception-
The System.Exception associated with the failure.
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
errorMessage
string-
The error message associated with the failure.
ex
Exception-
The System.Exception associated with the failure.
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
error
IError-
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
errors
IEnumerable<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
errors
IReadOnlyList<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
errorMessage
string-
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
errorMessage
string-
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
errorMessage
string-
The error message associated with the failure.
metadata
KeyValuePair<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
errorMessage
string-
The error message associated with the failure.
metadata
IReadOnlyDictionary<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
ex
Exception-
The System.Exception associated with the failure.
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
errorMessage
string-
The error message associated with the failure.
ex
Exception-
The System.Exception associated with the failure.
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
error
IError-
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
errors
IEnumerable<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
errors
IReadOnlyList<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 : IError
Returns
- bool
-
true
if 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 : IError
Parameters
error
TError-
The error of the specified type.
Returns
- bool
-
true
if an error of the specified type exists; otherwise,false
.
Type Parameters
TError
-
The type of error to check for.
IsFailure()
Determines whether the result failure.
public bool IsFailure()
Returns
- bool
-
true
if the result failure; otherwise,false
.
IsFailure(out IError)
Determines whether the result failure.
public bool IsFailure(out IError error)
Parameters
error
IError-
The error of the result.
Returns
- bool
-
true
if the result failure; otherwise,false
.
IsSuccess()
Determines whether the result was successful.
public bool IsSuccess()
Returns
- bool
-
true
if 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 with the specified value.
Success<TValue>(TValue)
Creates a success result with the specified value.
public static Result<TValue> Success<TValue>(TValue value)
Parameters
value
TValue-
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 ==(Result, Result)
Determines whether two LightResults.Result instances are equal.
public static bool operator ==(Result left, Result right)
Parameters
left
Result-
The first LightResults.Result instance to compare.
right
Result-
The second LightResults.Result instance to compare.
Returns
- bool
-
true
if 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
error
Error-
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 !=(Result, Result)
Determines whether two LightResults.Result instances are not equal.
public static bool operator !=(Result left, Result right)
Parameters
left
Result-
The first LightResults.Result instance to compare.
right
Result-
The second LightResults.Result instance to compare.
Returns
- bool
-
true
if the specified LightResults.Result instances are not equal; otherwise,false
.