API Reference ResultConversionExtensions - ulfbou/Zentient.Results GitHub Wiki
namespace Zentient.ResultsProvides extension methods for IResult and IResult<T> enabling fluent conversions and introspection of result state, error data, and metadata. Facilitates seamless transformations between non-generic and generic results and extraction of diagnostic information.
| Property | Value |
|---|---|
| 📦 Assembly | Zentient.Results.dll |
| 👁️ Visibility | public static |
| ⚙️ Type Kind | static class |
public static IResult<bool> ToBoolResult(this IResult result)Converts a non-generic IResult into a generic IResult<bool>:
- Success maps to
true - Failure maps to
false
Preserves all error information and messages.
| Parameter | Type | Description |
|---|---|---|
result |
IResult |
Source result object. |
| Returns | Description |
|---|---|
IResult<bool> |
Typed result reflecting boolean success. |
Throws
ArgumentNullExceptionifresultisnull.
public static string ToErrorString(this IResult result, string separator = "; ")Concatenates all error messages from a failure result into a single string separated by the specified delimiter.
| Parameter | Type | Description |
|---|---|---|
result |
IResult |
The result instance to inspect. |
separator |
string |
Delimiter between error messages. Defaults to "; ". |
| Returns | Description |
|---|---|
string |
Concatenated error messages or empty string if none. |
Throws
ArgumentNullExceptionifresultisnull.
public static string? FirstErrorMessage(this IResult result)Retrieves the message from the first error in a failure result, or null if none exists.
| Parameter | Type | Description |
|---|---|---|
result |
IResult |
The result to extract message from. |
| Returns | Description |
|---|---|
string? |
First error message or null. |
Throws
ArgumentNullExceptionifresultisnull.
These extension methods improve developer ergonomics for common operations:
- Bridging non-generic and generic results seamlessly (
ToBoolResult) - Generating human-readable error diagnostics (
ToErrorString,FirstErrorMessage) - Ensuring consistent handling across logging, telemetry, and transport layers
var operationResult = someService.PerformAction();
IResult<bool> boolResult = operationResult.ToBoolResult();
if (boolResult.IsFailure)
{
logger.LogWarning("Operation failed with errors: " + operationResult.ToErrorString());
}