Table of Contents

Class Convertible

Namespace
Cuemon
Assembly
Cuemon.Kernel.dll

Provides static helper methods for converting IConvertible values to and from byte arrays, including support for configurable encoding, byte order, and custom converters.

public static class Convertible
Inheritance
Convertible

Fields

BitsPerByte

Represents the number of bits in a byte.

public const int BitsPerByte = 8

Field Value

int

BitsPerNibble

Represents the number of bits in a nibble.

public const int BitsPerNibble = 4

Field Value

int

NullValue

Represents a null value when converting to a byte array.

public const int NullValue = 0

Field Value

int

Methods

GetBytes(bool, Action<EndianOptions>)

Converts the specified bool value to its byte array representation.

public static byte[] GetBytes(bool input, Action<EndianOptions> setup = null)

Parameters

input bool

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(byte, Action<EndianOptions>)

Converts the specified byte value to its byte array representation.

public static byte[] GetBytes(byte input, Action<EndianOptions> setup = null)

Parameters

input byte

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(char, Action<EndianOptions>)

Converts the specified char value to its byte array representation.

public static byte[] GetBytes(char input, Action<EndianOptions> setup = null)

Parameters

input char

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(IEnumerable<IConvertible>, Action<ConvertibleOptions>)

Converts the specified sequence of IConvertible values to a single aggregated byte array.

public static byte[] GetBytes(IEnumerable<IConvertible> input, Action<ConvertibleOptions> setup = null)

Parameters

input IEnumerable<IConvertible>

The sequence of values to convert.

setup Action<ConvertibleOptions>

The delegate that configures the conversion options.

Returns

byte[]

A byte array containing the concatenated byte representations of the elements in input.

GetBytes(DBNull)

Converts the specified DBNull value to its byte array representation.

public static byte[] GetBytes(DBNull input)

Parameters

input DBNull

The value to convert.

Returns

byte[]

A byte array representing NullValue.

GetBytes(DateTime)

Converts the specified DateTime value to its byte array representation.

public static byte[] GetBytes(DateTime input)

Parameters

input DateTime

The value to convert.

Returns

byte[]

A byte array that represents input.

Remarks

The value is formatted using the universal sortable date and time pattern and encoded with ASCII.

GetBytes(decimal)

Converts the specified decimal value to its byte array representation.

public static byte[] GetBytes(decimal input)

Parameters

input decimal

The value to convert.

Returns

byte[]

A byte array that represents input.

Remarks

The value is formatted using the invariant culture and encoded with ASCII.

GetBytes(double, Action<EndianOptions>)

Converts the specified double value to its byte array representation.

public static byte[] GetBytes(double input, Action<EndianOptions> setup = null)

Parameters

input double

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(Enum, Action<EndianOptions>)

Converts the specified Enum value to its underlying byte array representation.

public static byte[] GetBytes(Enum input, Action<EndianOptions> setup = null)

Parameters

input Enum

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents the underlying numeric value of input.

GetBytes(IConvertible, Action<ConvertibleOptions>)

Converts the specified IConvertible value to its byte array representation.

public static byte[] GetBytes(IConvertible input, Action<ConvertibleOptions> setup = null)

Parameters

input IConvertible

The value to convert.

setup Action<ConvertibleOptions>

The delegate that configures the conversion options.

Returns

byte[]

A byte array that represents input.

Remarks

Returns the byte representation of NullValue when input is null. Custom converters may be registered globally with RegisterConvertible<T>(Func<T, byte[]>) or supplied locally through Converters.

Exceptions

ArgumentOutOfRangeException

input is of a type for which no converter has been registered or configured.

GetBytes(short, Action<EndianOptions>)

Converts the specified short value to its byte array representation.

public static byte[] GetBytes(short input, Action<EndianOptions> setup = null)

Parameters

input short

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(int, Action<EndianOptions>)

Converts the specified int value to its byte array representation.

public static byte[] GetBytes(int input, Action<EndianOptions> setup = null)

Parameters

input int

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(long, Action<EndianOptions>)

Converts the specified long value to its byte array representation.

public static byte[] GetBytes(long input, Action<EndianOptions> setup = null)

Parameters

input long

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(sbyte, Action<EndianOptions>)

Converts the specified sbyte value to its byte array representation.

public static byte[] GetBytes(sbyte input, Action<EndianOptions> setup = null)

Parameters

input sbyte

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(float, Action<EndianOptions>)

Converts the specified float value to its byte array representation.

public static byte[] GetBytes(float input, Action<EndianOptions> setup = null)

Parameters

input float

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(string, Action<EncodingOptions>)

Converts the specified string value to its byte array representation.

public static byte[] GetBytes(string input, Action<EncodingOptions> setup = null)

Parameters

input string

The value to convert.

setup Action<EncodingOptions>

The delegate that configures the encoding behavior.

Returns

byte[]

A byte array that represents input.

Remarks

Exceptions

ArgumentNullException

input is null.

InvalidEnumArgumentException

setup configures an invalid value for Preamble.

GetBytes(ushort, Action<EndianOptions>)

Converts the specified ushort value to its byte array representation.

public static byte[] GetBytes(ushort input, Action<EndianOptions> setup = null)

Parameters

input ushort

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(uint, Action<EndianOptions>)

Converts the specified uint value to its byte array representation.

public static byte[] GetBytes(uint input, Action<EndianOptions> setup = null)

Parameters

input uint

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

GetBytes(ulong, Action<EndianOptions>)

Converts the specified ulong value to its byte array representation.

public static byte[] GetBytes(ulong input, Action<EndianOptions> setup = null)

Parameters

input ulong

The value to convert.

setup Action<EndianOptions>

The delegate that configures the byte order.

Returns

byte[]

A byte array that represents input.

RegisterConvertible<T>(Func<T, byte[]>)

Registers a custom converter for the specified IConvertible implementation.

public static void RegisterConvertible<T>(Func<T, byte[]> converter) where T : IConvertible

Parameters

converter Func<T, byte[]>

The delegate that converts an instance of T to a byte array.

Type Parameters

T

The type of the IConvertible implementation to register.

Exceptions

ArgumentNullException

converter is null.

ReverseBits16(ushort)

Reverses the bit order of the specified 16-bit unsigned integer.

public static ushort ReverseBits16(ushort input)

Parameters

input ushort

The value whose bits to reverse.

Returns

ushort

A ushort whose bits are reversed.

ReverseBits32(uint)

Reverses the bit order of the specified 32-bit unsigned integer.

public static uint ReverseBits32(uint input)

Parameters

input uint

The value whose bits to reverse.

Returns

uint

A uint whose bits are reversed.

ReverseBits64(ulong)

Reverses the bit order of the specified 64-bit unsigned integer.

public static ulong ReverseBits64(ulong input)

Parameters

input ulong

The value whose bits to reverse.

Returns

ulong

A ulong whose bits are reversed.

ReverseBits8(byte)

Reverses the bit order of the specified 8-bit unsigned integer.

public static byte ReverseBits8(byte input)

Parameters

input byte

The value whose bits to reverse.

Returns

byte

A byte whose bits are reversed.

ReverseEndianness(byte[], Action<EndianOptions>)

Reverses the byte order of the specified byte array when required by the configured endianness.

public static byte[] ReverseEndianness(byte[] input, Action<EndianOptions> setup = null)

Parameters

input byte[]

The byte array whose byte order to reverse.

setup Action<EndianOptions>

The delegate that configures the desired byte order.

Returns

byte[]

input, either unchanged or reversed to match the configured byte order.

ToString(byte[], Action<EncodingOptions>)

Converts the specified byte array to its string representation.

public static string ToString(byte[] input, Action<EncodingOptions> setup = null)

Parameters

input byte[]

The byte array to convert.

setup Action<EncodingOptions>

The delegate that configures the encoding behavior.

Returns

string

A string that represents input.

Remarks

EncodingOptions is initialized with DefaultPreambleSequence and DefaultEncoding. If the configured encoding is the default encoding, the encoding is detected from the byte order mark when possible.

Exceptions

ArgumentNullException

input is null.

InvalidEnumArgumentException

setup configures an invalid value for Preamble.