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(Boolean, Action<EndianOptions>)
Returns the specified Boolean as a byte[].
public static byte[] GetBytes(bool input, Action<EndianOptions> setup = null)
Parameters
input
BooleanThe Boolean 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(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(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(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(Int16, Action<EndianOptions>)
Returns the specified Int16 as a byte[].
public static byte[] GetBytes(short input, Action<EndianOptions> setup = null)
Parameters
input
Int16The Int16 to convert.
setup
Action<EndianOptions>The EndianOptions which may be configured.
Returns
- Byte[]
A byte[] that is equivalent to
input
.
GetBytes(Int32, Action<EndianOptions>)
Returns the specified Int32 as a byte[].
public static byte[] GetBytes(int input, Action<EndianOptions> setup = null)
Parameters
input
Int32The Int32 to convert.
setup
Action<EndianOptions>The EndianOptions which may be configured.
Returns
- Byte[]
A byte[] that is equivalent to
input
.
GetBytes(Int64, Action<EndianOptions>)
Returns the specified Int64 as a byte[].
public static byte[] GetBytes(long input, Action<EndianOptions> setup = null)
Parameters
input
Int64The Int64 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(Single, Action<EndianOptions>)
Returns the specified Single as a byte[].
public static byte[] GetBytes(float input, Action<EndianOptions> setup = null)
Parameters
input
SingleThe Single 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(UInt16, Action<EndianOptions>)
Returns the specified UInt16 as a byte[].
public static byte[] GetBytes(ushort input, Action<EndianOptions> setup = null)
Parameters
input
UInt16The UInt16 to convert.
setup
Action<EndianOptions>The EndianOptions which may be configured.
Returns
- Byte[]
A byte[] that is equivalent to
input
.
GetBytes(UInt32, Action<EndianOptions>)
Returns the specified UInt32 as a byte[].
public static byte[] GetBytes(uint input, Action<EndianOptions> setup = null)
Parameters
input
UInt32The UInt32 to convert.
setup
Action<EndianOptions>The EndianOptions which may be configured.
Returns
- Byte[]
A byte[] that is equivalent to
input
.
GetBytes(UInt64, Action<EndianOptions>)
Returns the specified UInt64 as a byte[].
public static byte[] GetBytes(ulong input, Action<EndianOptions> setup = null)
Parameters
input
UInt64The UInt64 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(UInt16)
Reverse the bits of the specified input
.
public static ushort ReverseBits16(ushort input)
Parameters
input
UInt16The unsigned 16-bit integer to reverse bits on.
Returns
ReverseBits32(UInt32)
Reverse the bits of the specified input
.
public static uint ReverseBits32(uint input)
Parameters
input
UInt32The unsigned 32-bit integer to reverse bits on.
Returns
ReverseBits64(UInt64)
Reverse the bits of the specified input
.
public static ulong ReverseBits64(ulong input)
Parameters
input
UInt64The 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.