API Reference ResultConversionExtensions - ulfbou/Zentient.Results GitHub Wiki

📘 API Reference: static classZentient.Results.ResultConversionExtensions

namespace Zentient.Results

📖 Summary

Provides 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.


📌 Metadata

Property Value
📦 Assembly Zentient.Results.dll
👁️ Visibility public static
⚙️ Type Kind static class

🔧 Extension Methods

🔄 ToBoolResult

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 ArgumentNullException if result is null.


📛 ToErrorString

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 ArgumentNullException if result is null.


⚠️ FirstErrorMessage

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 ArgumentNullException if result is null.


🧠 Remarks

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

✅ Example Usage

var operationResult = someService.PerformAction();

IResult<bool> boolResult = operationResult.ToBoolResult();

if (boolResult.IsFailure)
{
    logger.LogWarning("Operation failed with errors: " + operationResult.ToErrorString());
}
⚠️ **GitHub.com Fallback** ⚠️