Struct Outcome<T>
- Namespace
- Kevlar
- Assembly
- Kevlar.dll
The result of an execution: either a value or a captured exception, never both. Kevlar strategies pass outcomes between pipeline layers instead of throwing, so exceptions only pay their cost once, at the pipeline boundary.
public readonly struct Outcome<T>
Type Parameters
TThe result type of the execution.
- Inherited Members
Properties
Exception
The captured exception, or null if the execution produced a result.
public Exception? Exception { get; }
Property Value
IsSuccess
true when the execution produced a result rather than an exception.
public bool IsSuccess { get; }
Property Value
Result
The result value. Only meaningful when Exception is null. For flow-analysis-friendly access, use TryGetResult(out T).
public T? Result { get; }
Property Value
- T
Methods
FromException(Exception)
Creates an outcome holding a captured exception.
public static Outcome<T> FromException(Exception exception)
Parameters
exceptionException
Returns
- Outcome<T>
FromResult(T)
Creates an outcome holding a result value.
public static Outcome<T> FromResult(T result)
Parameters
resultT
Returns
- Outcome<T>
GetResultOrRethrow()
Returns the result, or rethrows the captured exception with its original stack trace preserved.
public T GetResultOrRethrow()
Returns
- T
ToString()
public override string ToString()
Returns
TryGetResult(out T)
Tries to get the result without throwing the captured exception.
public bool TryGetResult(out T result)
Parameters
resultTThe result value when the outcome is successful; otherwise, the default value of
T.
Returns
Operators
implicit operator Outcome(Outcome<T>)
Converts a result-bearing outcome to its void success-or-failure representation.
public static implicit operator Outcome(Outcome<T> outcome)
Parameters
outcomeOutcome<T>