Table of Contents

Class Result

Namespace
FoundationaLLM.Common.Models.Services
Assembly
FoundationaLLM.Common.dll

Represents the outcome of an operation, indicating either success or failure and providing error information if applicable.

public class Result
Inheritance
Result
Inherited Members
Extension Methods

Remarks

Use the Result class to encapsulate the success or failure state of an operation without relying on exceptions for control flow. When a failure occurs, the associated error can be accessed through the Error property. For results that carry a value on success, use the generic Result<T> type.

Properties

Error

Gets the error associated with a failure result.

[JsonPropertyName("error")]
public DomainError? Error { get; }

Property Value

DomainError

IsFailure

Gets a value indicating whether the result represents a failure state.

[JsonIgnore]
public bool IsFailure { get; }

Property Value

bool

IsSuccess

Gets a value indicating whether the result refers to a successful outcome.

[JsonPropertyName("is_success")]
public bool IsSuccess { get; }

Property Value

bool

Methods

Failure(DomainError)

Creates a failed result with the specified domain error.

public static Result Failure(DomainError error)

Parameters

error DomainError

The domain error that describes the reason for the failure. Cannot be null.

Returns

Result

A Result instance representing a failure with the provided domain error.

FailureFromErrorMessage(string, int, string?)

Creates a failed result with the specified error message.

public static Result FailureFromErrorMessage(string errorMessage, int status = 500, string? instance = null)

Parameters

errorMessage string

The error message that describes the reason for the failure. Cannot be null or empty.

status int

The status code associated with the exception.

instance string

An optional instance identifier for the error.

Returns

Result

A failed result containing the specified error message.

FailureFromException(Exception, int, string?)

Creates a failed result that represents the specified exception.

public static Result FailureFromException(Exception exception, int status = 500, string? instance = null)

Parameters

exception Exception

The exception to convert into a failure result. Cannot be null.

status int

The status code associated with the exception.

instance string

An optional instance identifier for the error.

Returns

Result

A failed result containing error information derived from the specified exception.

FailureFromHttpResponse(HttpResponseMessage)

Creates a failed result based on the error information extracted from the specified HTTP response.

public static Task<Result> FailureFromHttpResponse(HttpResponseMessage response)

Parameters

response HttpResponseMessage

The HTTP response message from which to extract error details. Cannot be null.

Returns

Task<Result>

A task that represents the asynchronous operation. The task result contains a failed result populated with error information from the HTTP response.

Success()

Creates a successful result.

public static Result Success()

Returns

Result

A Result object indicating success.

ToActionResult()

Converts the current result to an appropriate ActionResult for use in ASP.NET Core MVC controllers.

public ActionResult ToActionResult()

Returns

ActionResult

An OkResult if the operation was successful; otherwise, an ObjectResult containing the ProblemDetails object with error information.

Remarks

Use this method to translate the result of an operation into a standardized HTTP response for controller actions. The returned result can be returned directly from an action method.