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
BitsPerNibble
Defines how many bits is needed for one nibble (one hexadecimal digit).
public const int BitsPerNibble = 4
Field Value
NullValue
A representation for a null value when converting to a byte[].
public const int NullValue = 0
Field Value
Methods
GetBytes(bool, Action<EndianOptions>)
Returns the specified bool as a byte[].
public static byte[] GetBytes(bool input, Action<EndianOptions> setup = null)
Parameters
input
boolThe 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
byteThe 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
charThe 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
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
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
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
doubleThe 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
EnumThe 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
IConvertibleThe 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
shortThe 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
intThe 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
longThe 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
sbyteThe 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
floatThe 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
stringThe string to convert.
setup
Action<EncodingOptions>The EncodingOptions which may be configured.
Returns
- byte[]
A byte[] that is equivalent to
input
.
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
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
ushortThe 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
uintThe 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
ulongThe 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
ushortThe unsigned 16-bit integer to reverse bits on.
Returns
ReverseBits32(uint)
Reverse the bits of the specified input
.
public static uint ReverseBits32(uint input)
Parameters
input
uintThe unsigned 32-bit integer to reverse bits on.
Returns
ReverseBits64(ulong)
Reverse the bits of the specified input
.
public static ulong ReverseBits64(ulong input)
Parameters
input
ulongThe unsigned 64-bit integer to reverse bits on.
Returns
ReverseBits8(byte)
Reverse the bits of the specified input
.
public static byte ReverseBits8(byte input)
Parameters
input
byteThe unsigned 8-bit integer to reverse bits on.
Returns
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 ofinput
.
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
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
- ArgumentNullException
input
cannot be null.- InvalidEnumArgumentException
setup
was initialized with an invalid Preamble.