API Reference ResultStatusExtensions - ulfbou/Zentient.Results GitHub Wiki
API Reference: ResultStatusExtensions
1. ResultStatusExtensions
1.1. Overview
- Namespace:
Zentient.Results
- Type:
Static Class
- Summary: Provides extension methods for
IResultStatus
, offering convenient utility functions to interact with or convert result status objects.
1.2. Design Philosophy / Rationale
ResultStatusExtensions
follows the common .NET pattern of using extension methods to add functionality to existing types (in this case, IResultStatus
) without modifying their original definition. This keeps the IResultStatus
interface clean and focused on its core contract, while providing practical utilities that enhance developer experience and simplify common tasks, such as mapping a result status to an HTTP status code.
2. Methods
ToHttpStatusCode(this IResultStatus status)
2.1. - Signature:
public static int ToHttpStatusCode(this IResultStatus status)
- Summary: Converts an
IResultStatus
instance to its corresponding integer HTTP status code. - Parameters:
status
(this IResultStatus
): TheIResultStatus
instance to convert.
- Return Value: (
int
): The integer value of theStatus.Code
property. - Behavior: This method simply returns the
Code
property of theIResultStatus
object, which is typically designed to align with HTTP status codes for standard outcomes. - Example Usage:
IResultStatus successStatus = ResultStatuses.Success; int httpCode = successStatus.ToHttpStatusCode(); // httpCode will be 200 IResultStatus notFoundStatus = ResultStatuses.NotFound; int notFoundCode = notFoundStatus.ToHttpStatusCode(); // notFoundCode will be 404
7. Remarks / Additional Notes
- Convenience: This extension method provides a direct and readable way to extract the HTTP status code from any
IResultStatus
implementation, making it particularly useful when building web API responses or integrating with HTTP-aware clients. - Consistency: It reinforces the convention that the
Code
property ofIResultStatus
should be an HTTP-compatible status code for standard results.
Last Updated: 2025-06-08 Version: 0.3.0