Class OperationResult
- Namespace
- AsiBackbone.Core.Results
- Assembly
- AsiBackbone.Core.dll
Represents the framework-neutral outcome of an operation.
public class OperationResult
- Inheritance
-
OperationResult
- Derived
-
OperationResult<TValue>
- Inherited Members
Constructors
OperationResult(bool, IReadOnlyList<OperationReason>, IReadOnlyList<string>)
Initializes a new instance of the OperationResult class.
protected OperationResult(bool succeeded, IReadOnlyList<OperationReason> reasons, IReadOnlyList<string> warnings)
Parameters
succeededboolA value indicating whether the operation succeeded.
reasonsIReadOnlyList<OperationReason>The reasons associated with the operation result.
warningsIReadOnlyList<string>The warnings associated with the operation result.
Properties
Failed
Gets a value indicating whether the operation failed.
public bool Failed { get; }
Property Value
HasWarnings
Gets a value indicating whether the operation result has warning messages.
public bool HasWarnings { get; }
Property Value
ReasonCodes
Gets machine-readable reason codes associated with the operation result.
public IReadOnlyList<string> ReasonCodes { get; }
Property Value
Reasons
Gets the reasons associated with the operation result.
public IReadOnlyList<OperationReason> Reasons { get; }
Property Value
Succeeded
Gets a value indicating whether the operation succeeded.
public bool Succeeded { get; }
Property Value
Warnings
Gets human-readable warning messages associated with the operation result.
public IReadOnlyList<string> Warnings { get; }
Property Value
Methods
Failure()
Creates a failed operation result using the default failure reason.
public static OperationResult Failure()
Returns
- OperationResult
A failed operation result.
Failure(OperationReason)
Creates a failed operation result.
public static OperationResult Failure(OperationReason reason)
Parameters
reasonOperationReasonThe reason associated with the failed result.
Returns
- OperationResult
A failed operation result.
Failure(IEnumerable<OperationReason>)
Creates a failed operation result.
public static OperationResult Failure(IEnumerable<OperationReason> reasons)
Parameters
reasonsIEnumerable<OperationReason>The reasons associated with the failed result.
Returns
- OperationResult
A failed operation result.
Failure(IEnumerable<OperationReason>, IEnumerable<string>)
Creates a failed operation result with warnings.
public static OperationResult Failure(IEnumerable<OperationReason> reasons, IEnumerable<string> warnings)
Parameters
reasonsIEnumerable<OperationReason>The reasons associated with the failed result.
warningsIEnumerable<string>The warnings associated with the failed result.
Returns
- OperationResult
A failed operation result.
Failure(string, string)
Creates a failed operation result.
public static OperationResult Failure(string code, string message)
Parameters
Returns
- OperationResult
A failed operation result.
Failure<TValue>()
Creates a failed operation result using the default failure reason.
public static OperationResult<TValue> Failure<TValue>()
Returns
- OperationResult<TValue>
A failed operation result.
Type Parameters
TValueThe result value type.
Failure<TValue>(OperationReason)
Creates a failed operation result.
public static OperationResult<TValue> Failure<TValue>(OperationReason reason)
Parameters
reasonOperationReasonThe reason associated with the failed result.
Returns
- OperationResult<TValue>
A failed operation result.
Type Parameters
TValueThe result value type.
Failure<TValue>(IEnumerable<OperationReason>)
Creates a failed operation result.
public static OperationResult<TValue> Failure<TValue>(IEnumerable<OperationReason> reasons)
Parameters
reasonsIEnumerable<OperationReason>The reasons associated with the failed result.
Returns
- OperationResult<TValue>
A failed operation result.
Type Parameters
TValueThe result value type.
Failure<TValue>(IEnumerable<OperationReason>, IEnumerable<string>)
Creates a failed operation result with warnings.
public static OperationResult<TValue> Failure<TValue>(IEnumerable<OperationReason> reasons, IEnumerable<string> warnings)
Parameters
reasonsIEnumerable<OperationReason>The reasons associated with the failed result.
warningsIEnumerable<string>The warnings associated with the failed result.
Returns
- OperationResult<TValue>
A failed operation result.
Type Parameters
TValueThe result value type.
Failure<TValue>(string, string)
Creates a failed operation result.
public static OperationResult<TValue> Failure<TValue>(string code, string message)
Parameters
Returns
- OperationResult<TValue>
A failed operation result.
Type Parameters
TValueThe result value type.
NormalizeReasons(IEnumerable<OperationReason>?)
Normalizes operation reasons and provides a default failure reason when none are supplied.
protected static IReadOnlyList<OperationReason> NormalizeReasons(IEnumerable<OperationReason>? reasons)
Parameters
reasonsIEnumerable<OperationReason>The reasons to normalize.
Returns
- IReadOnlyList<OperationReason>
A normalized reason collection.
NormalizeWarnings(IEnumerable<string>?)
Normalizes warning messages.
protected static IReadOnlyList<string> NormalizeWarnings(IEnumerable<string>? warnings)
Parameters
warningsIEnumerable<string>The warnings to normalize.
Returns
- IReadOnlyList<string>
A normalized warning collection.
Success()
Creates a successful operation result.
public static OperationResult Success()
Returns
- OperationResult
A successful operation result.
Success(IEnumerable<string>)
Creates a successful operation result with warnings.
public static OperationResult Success(IEnumerable<string> warnings)
Parameters
warningsIEnumerable<string>The warnings associated with the successful result.
Returns
- OperationResult
A successful operation result.
Success<TValue>(TValue)
Creates a successful operation result with a value.
public static OperationResult<TValue> Success<TValue>(TValue value)
Parameters
valueTValueThe operation value.
Returns
- OperationResult<TValue>
A successful operation result.
Type Parameters
TValueThe result value type.
Success<TValue>(TValue, IEnumerable<string>)
Creates a successful operation result with a value and warnings.
public static OperationResult<TValue> Success<TValue>(TValue value, IEnumerable<string> warnings)
Parameters
valueTValueThe operation value.
warningsIEnumerable<string>The warnings associated with the successful result.
Returns
- OperationResult<TValue>
A successful operation result.
Type Parameters
TValueThe result value type.
ToFailure()
Creates a failed operation result from this result's reasons and warnings.
public OperationResult ToFailure()
Returns
- OperationResult
A failed operation result.