Table of Contents

Class Int32DecoratorExtensions

Namespace
Cuemon.AspNetCore.Http
Assembly
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

IsClientErrorStatusCode(IDecorator<int>)

Determines whether the enclosed int of the decorator is within the client error related range.

public static bool IsClientErrorStatusCode(this IDecorator<int> decorator)

Parameters

decorator IDecorator<int>

The IDecorator<T> to extend.

Returns

bool

true if the enclosed int of the decorator was in the Client Error range (400-499); otherwise, false.

Exceptions

ArgumentNullException

decorator cannot be null.

IsInformationStatusCode(IDecorator<int>)

Determines whether the enclosed int of the decorator is within the informational range.

public static bool IsInformationStatusCode(this IDecorator<int> decorator)

Parameters

decorator IDecorator<int>

The IDecorator<T> to extend.

Returns

bool

true if the enclosed int of the decorator was in the Information range (100-199); otherwise, false.

Exceptions

ArgumentNullException

decorator cannot be null.

IsNotModifiedStatusCode(IDecorator<int>)

Determines whether the enclosed int of the decorator equals a 304 Not Modified.

public static bool IsNotModifiedStatusCode(this IDecorator<int> decorator)

Parameters

decorator IDecorator<int>

The IDecorator<T> to extend.

Returns

bool

true if the enclosed int of the decorator is NotModified (304); otherwise, false.

Exceptions

ArgumentNullException

decorator cannot be null.

IsRedirectionStatusCode(IDecorator<int>)

Determines whether the enclosed int of the decorator is within the redirecting range.

public static bool IsRedirectionStatusCode(this IDecorator<int> decorator)

Parameters

decorator IDecorator<int>

The IDecorator<T> to extend.

Returns

bool

true if the enclosed int of the decorator was in the Redirection range (300-399); otherwise, false.

Exceptions

ArgumentNullException

decorator cannot be null.

IsServerErrorStatusCode(IDecorator<int>)

Determines whether the enclosed int of the decorator is within the server error related range.

public static bool IsServerErrorStatusCode(this IDecorator<int> decorator)

Parameters

decorator IDecorator<int>

The IDecorator<T> to extend.

Returns

bool

true if the enclosed int of the decorator was in the Server Error range (500-599); otherwise, false.

Exceptions

ArgumentNullException

decorator cannot be null.

IsSuccessStatusCode(IDecorator<int>)

Determines whether the enclosed int of the decorator is within the successful range.

public static bool IsSuccessStatusCode(this IDecorator<int> decorator)

Parameters

decorator IDecorator<int>

The IDecorator<T> to extend.

Returns

bool

true if the enclosed int of the decorator was in the Successful range (200-299); otherwise, false.

Exceptions

ArgumentNullException

decorator cannot be null.

See Also