Skip to content

OnixLabs.Core.Text.Base16FormatProvider

matthew edited this page May 27, 2026 · 1 revision

Base16FormatProvider Class

Represents a Base-16 format provider.

Namespace OnixLabs.Core.Text
Assembly OnixLabs.Core.dll (NuGet)
Inheritance object → Enumeration<Base16FormatProvider> → Base16FormatProvider
Implements IEquatable<Base16FormatProvider>, IComparable<Base16FormatProvider>, IComparable, IFormatProvider

Definition

public sealed class Base16FormatProvider : Enumeration<Base16FormatProvider>, IFormatProvider

Remarks

Base16FormatProvider is a smart enumeration that carries the alphabet used by Base16Codec to encode and decode Base-16 (hexadecimal) values. It derives from Enumeration<Base16FormatProvider> and implements IFormatProvider, so it integrates naturally with any API that accepts an IFormatProvider.

Three entries are declared: Invariant accepts both uppercase and lowercase hexadecimal characters on decode and produces lowercase output; Uppercase enforces strict uppercase; Lowercase enforces strict lowercase. Supplying an Uppercase provider when decoding a lowercase string, or vice versa, causes TryDecode to return false and Decode to throw FormatException.

Because the type derives from Enumeration<T>, all entries are also available through the inherited static query methods such as GetAll, FromName, and FromValue.

Fields

All fields are declared as public static readonly Base16FormatProvider.

Field Description
Invariant The invariant Base-16 format provider. Favors lowercase output; its alphabet "0123456789ABCDEFabcdef" is not a strict Base-16 alphabet as it contains both uppercase and lowercase values.
Uppercase The uppercase Base-16 format provider. Alphabet "0123456789ABCDEF".
Lowercase The lowercase Base-16 format provider. Alphabet "0123456789abcdef".

Invariant

public static readonly Base16FormatProvider Invariant;

The invariant Base-16 format provider. Favors lowercase output during encoding. Its alphabet "0123456789ABCDEFabcdef" is not a strict Base-16 alphabet — it contains both uppercase and lowercase letters, allowing it to accept mixed-case input during decoding.

Uppercase

public static readonly Base16FormatProvider Uppercase;

The uppercase Base-16 format provider. Alphabet "0123456789ABCDEF". Encoded output contains only uppercase hexadecimal characters. Decoding rejects input that contains lowercase letters.

Lowercase

public static readonly Base16FormatProvider Lowercase;

The lowercase Base-16 format provider. Alphabet "0123456789abcdef". Encoded output contains only lowercase hexadecimal characters. Decoding rejects input that contains uppercase letters.

Properties

Property Type Description
Alphabet string Gets the Base-16 alphabet associated with the current format provider.

Alphabet

public string Alphabet { get; }

Gets the alphabet of the current Base16FormatProvider instance.

Methods

Method Returns Description
GetFormat(Type?) object? Returns the current instance when formatType is typeof(Base16FormatProvider); otherwise, returns null.

GetFormat(Type?)

public object? GetFormat(Type? formatType)

Returns the current instance when formatType is typeof(Base16FormatProvider); otherwise, returns null. This is the IFormatProvider contract method that allows the format provider to be passed to any API that accepts IFormatProvider.

Parameter Type Description
formatType Type? The type of format object to obtain.

Returns — The current instance if formatType is typeof(Base16FormatProvider); otherwise, null.

See Also

ONIXLabs .NET Library


Clone this wiki locally