Int32DecoratorExtensions Class
Definition
- Namespace
- Cuemon.AspNetCore.Http
- Assemblies
- Cuemon.AspNetCore.dll
Extension methods for the int struct hidden behind the IDecorator<T> interface.
public static class Int32DecoratorExtensions
- Inheritance
-
Int32DecoratorExtensions
Examples
The following example demonstrates how to use the Int32DecoratorExtensions extension methods to classify HTTP status codes through the Decorator<T> pattern.
using System;
using Cuemon;
using Cuemon.AspNetCore.Http;
namespace MyApp.Examples;
public class Example
{
public void Run()
{
int statusCode = 500;
// Wrap the int in a Decorator and use the extension methods
var decorator = Decorator.Enclose(statusCode);
bool isInfo = decorator.IsInformationStatusCode();
bool isSuccess = decorator.IsSuccessStatusCode();
bool isRedirect = decorator.IsRedirectionStatusCode();
bool isClientError = decorator.IsClientErrorStatusCode();
bool isServerError = decorator.IsServerErrorStatusCode();
bool isNotModified = decorator.IsNotModifiedStatusCode();
Console.WriteLine($"HTTP {statusCode}:");
Console.WriteLine($" Informational (100-199): {isInfo}");
Console.WriteLine($" Successful (200-299): {isSuccess}");
Console.WriteLine($" Redirection (300-399): {isRedirect}");
Console.WriteLine($" Client Error (400-499): {isClientError}");
Console.WriteLine($" Server Error (500-599): {isServerError}");
Console.WriteLine($" Not Modified (304): {isNotModified}");
// Use with a success status code
int ok = 200;
var okDecorator = Decorator.Enclose(ok);
Console.WriteLine($"\n{ok} is success: {okDecorator.IsSuccessStatusCode()}"); // True
Console.WriteLine($"404 is client error: {Decorator.Enclose(404).IsClientErrorStatusCode()}"); // True
}
}
Methods
| Name | Description |
|---|---|
| IsClientErrorStatusCode(IDecorator<int>) | Determines whether the enclosed int of the |
| IsInformationStatusCode(IDecorator<int>) | Determines whether the enclosed int of the |
| IsNotModifiedStatusCode(IDecorator<int>) | Determines whether the enclosed int of the |
| IsRedirectionStatusCode(IDecorator<int>) | Determines whether the enclosed int of the |
| IsServerErrorStatusCode(IDecorator<int>) | Determines whether the enclosed int of the |
| IsSuccessStatusCode(IDecorator<int>) | Determines whether the enclosed int of the |