Table of Contents

Class Convertible

Namespace
Cuemon
Assembly
Cuemon.Core.dll

Provides a set of static methods, suitable for verifying integrity of data, that convert IConvertible implementations to and from a sequence of bytes.

public static class Convertible
Inheritance
Convertible

Fields

BitsPerByte

Defines how many bits is needed for one byte.

public const int BitsPerByte = 8

Field Value

int

BitsPerNibble

Defines how many bits is needed for one nibble (one hexadecimal digit).

public const int BitsPerNibble = 4

Field Value

int

NullValue

A representation for a null value when converting to a byte[].

public const int NullValue = 0

Field Value

int

Methods

GetBytes(bool, Action<EndianOptions>)

Returns the specified bool as a byte[].

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

Parameters

input bool

The bool to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(byte, Action<EndianOptions>)

Returns the specified byte as a byte[].

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

Parameters

input byte

The byte to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(char, Action<EndianOptions>)

Returns the specified char as a byte[].

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

Parameters

input char

The char to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

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

Returns the specified sequence of IConvertible as an aggregated byte[].

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

Parameters

input IEnumerable<IConvertible>

The IEnumerable<T> sequence to convert.

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

byte[]

An aggregated byte[] that is otherwise equivalent to input.

GetBytes(DBNull)

Returns the specified DBNull as a byte[].

public static byte[] GetBytes(DBNull input)

Parameters

input DBNull

The DBNull to convert.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(DateTime)

Returns the specified DateTime as a byte[].

public static byte[] GetBytes(DateTime input)

Parameters

input DateTime

The DateTime to convert.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(decimal)

Returns the specified decimal as a byte[].

public static byte[] GetBytes(decimal input)

Parameters

input decimal

The decimal to convert.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(double, Action<EndianOptions>)

Returns the specified double as a byte[].

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

Parameters

input double

The double to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(Enum, Action<EndianOptions>)

Returns the specified Enum as a byte[].

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

Parameters

input Enum

The Enum to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(IConvertible, Action<ConvertibleOptions>)

Returns the specified IConvertible as a byte[].

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

Parameters

input IConvertible

The IConvertible implementation to convert.

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

Exceptions

ArgumentOutOfRangeException

input is an unknown implementation of IConvertible; please use RegisterConvertible to make a custom implementation globally known -or- use setup to add a custom implementation using ConvertibleOptions.Converters..Add.

GetBytes(short, Action<EndianOptions>)

Returns the specified short as a byte[].

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

Parameters

input short

The short to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(int, Action<EndianOptions>)

Returns the specified int as a byte[].

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

Parameters

input int

The int to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(long, Action<EndianOptions>)

Returns the specified long as a byte[].

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

Parameters

input long

The long to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(sbyte, Action<EndianOptions>)

Returns the specified sbyte as a byte[].

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

Parameters

input sbyte

The sbyte to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(float, Action<EndianOptions>)

Returns the specified float as a byte[].

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

Parameters

input float

The float to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(string, Action<EncodingOptions>)

Returns the specified string as its equivalent byte[] representation.

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

Parameters

input string

The string to convert.

setup Action<EncodingOptions>

The EncodingOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

Remarks

Exceptions

ArgumentNullException

input cannot be null.

InvalidEnumArgumentException

setup was initialized with an invalid Preamble.

GetBytes(ushort, Action<EndianOptions>)

Returns the specified ushort as a byte[].

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

Parameters

input ushort

The ushort to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(uint, Action<EndianOptions>)

Returns the specified uint as a byte[].

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

Parameters

input uint

The uint to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

GetBytes(ulong, Action<EndianOptions>)

Returns the specified ulong as a byte[].

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

Parameters

input ulong

The ulong to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that is equivalent to input.

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

Registers the specified IConvertible implementation of T to make it globally known.

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

Parameters

converter Func<T, byte[]>

The function delegate that converts an IConvertible implementation to its equivalent byte[].

Type Parameters

T

The type of the IConvertible implementation to use.

Exceptions

ArgumentNullException

converter cannot be null.

ReverseBits16(ushort)

Reverse the bits of the specified input.

public static ushort ReverseBits16(ushort input)

Parameters

input ushort

The unsigned 16-bit integer to reverse bits on.

Returns

ushort

A ushort with the bits reversed.

ReverseBits32(uint)

Reverse the bits of the specified input.

public static uint ReverseBits32(uint input)

Parameters

input uint

The unsigned 32-bit integer to reverse bits on.

Returns

uint

A uint with the bits reversed.

ReverseBits64(ulong)

Reverse the bits of the specified input.

public static ulong ReverseBits64(ulong input)

Parameters

input ulong

The unsigned 64-bit integer to reverse bits on.

Returns

ulong

A ulong with the bits reversed.

ReverseBits8(byte)

Reverse the bits of the specified input.

public static byte ReverseBits8(byte input)

Parameters

input byte

The unsigned 8-bit integer to reverse bits on.

Returns

byte

A byte with the bits reversed.

ReverseEndianness(byte[], Action<EndianOptions>)

Reverse the endianness of the specified input.

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

Parameters

input byte[]

The byte[] to reverse.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

byte[]

A byte[] that, depending on the setup, is either equal or a reversed value of input.

ToString(byte[], Action<EncodingOptions>)

Returns the specified byte[] as its equivalent string representation.

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

Parameters

input byte[]

The byte[] to convert.

setup Action<EncodingOptions>

The EncodingOptions which may be configured.

Returns

string

A string that is equivalent to input.

Remarks

Exceptions

ArgumentNullException

input cannot be null.

InvalidEnumArgumentException

setup was initialized with an invalid Preamble.