Class Convertible
Provides a set of static methods, suitable for verifying integrity of data, that convert IConvertible implementations to and from a sequence of bytes.
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class Convertible
Fields
| Improve this Doc View SourceNullValue
A representation for a null value when converting to a byte[].
Declaration
public const int NullValue = 0
Field Value
Type | Description |
---|---|
Int32 |
Methods
| Improve this Doc View SourceGetBytes(Boolean, Action<EndianOptions>)
Returns the specified Boolean as a byte[].
Declaration
public static byte[] GetBytes(bool input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Boolean | input | The Boolean to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(Byte, Action<EndianOptions>)
Returns the specified Byte as a byte[].
Declaration
public static byte[] GetBytes(byte input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Byte | input | The Byte to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(Char, Action<EndianOptions>)
Returns the specified Char as a byte[].
Declaration
public static byte[] GetBytes(char input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Char | input | The Char to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(IEnumerable<IConvertible>, Action<ConvertibleOptions>)
Returns the specified sequence of IConvertible as an aggregated byte[].
Declaration
public static byte[] GetBytes(IEnumerable<IConvertible> input, Action<ConvertibleOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IConvertible> | input | The IEnumerable<T> sequence to convert. |
Action<ConvertibleOptions> | setup | The ConvertibleOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | An aggregated byte[] that is otherwise equivalent to |
GetBytes(DateTime)
Returns the specified DateTime as a byte[].
Declaration
public static byte[] GetBytes(DateTime input)
Parameters
Type | Name | Description |
---|---|---|
DateTime | input | The DateTime to convert. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(DBNull)
Returns the specified DBNull as a byte[].
Declaration
public static byte[] GetBytes(DBNull input)
Parameters
Type | Name | Description |
---|---|---|
DBNull | input | The DBNull to convert. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(Decimal)
Returns the specified Decimal as a byte[].
Declaration
public static byte[] GetBytes(decimal input)
Parameters
Type | Name | Description |
---|---|---|
Decimal | input | The Decimal to convert. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(Double, Action<EndianOptions>)
Returns the specified Double as a byte[].
Declaration
public static byte[] GetBytes(double input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Double | input | The Double to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(Enum, Action<EndianOptions>)
Returns the specified Enum as a byte[].
Declaration
public static byte[] GetBytes(Enum input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Enum | input | The Enum to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(IConvertible, Action<ConvertibleOptions>)
Returns the specified IConvertible as a byte[].
Declaration
public static byte[] GetBytes(IConvertible input, Action<ConvertibleOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
IConvertible | input | The IConvertible implementation to convert. |
Action<ConvertibleOptions> | setup | The ConvertibleOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
GetBytes(Int16, Action<EndianOptions>)
Returns the specified Int16 as a byte[].
Declaration
public static byte[] GetBytes(short input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Int16 | input | The Int16 to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(Int32, Action<EndianOptions>)
Returns the specified Int32 as a byte[].
Declaration
public static byte[] GetBytes(int input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | input | The Int32 to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(Int64, Action<EndianOptions>)
Returns the specified Int64 as a byte[].
Declaration
public static byte[] GetBytes(long input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Int64 | input | The Int64 to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(SByte, Action<EndianOptions>)
Returns the specified SByte as a byte[].
Declaration
public static byte[] GetBytes(sbyte input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
SByte | input | The SByte to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(Single, Action<EndianOptions>)
Returns the specified Single as a byte[].
Declaration
public static byte[] GetBytes(float input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Single | input | The Single to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(String, Action<EncodingOptions>)
Returns the specified String as its equivalent byte[] representation.
Declaration
public static byte[] GetBytes(string input, Action<EncodingOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
String | input | The String to convert. |
Action<EncodingOptions> | setup | The EncodingOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidEnumArgumentException |
|
GetBytes(UInt16, Action<EndianOptions>)
Returns the specified UInt16 as a byte[].
Declaration
public static byte[] GetBytes(ushort input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
UInt16 | input | The UInt16 to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(UInt32, Action<EndianOptions>)
Returns the specified UInt32 as a byte[].
Declaration
public static byte[] GetBytes(uint input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | input | The UInt32 to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
GetBytes(UInt64, Action<EndianOptions>)
Returns the specified UInt64 as a byte[].
Declaration
public static byte[] GetBytes(ulong input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | input | The UInt64 to convert. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that is equivalent to |
RegisterConvertible<T>(Func<T, Byte[]>)
Registers the specified IConvertible implementation of T
to make it globally known.
Declaration
public static void RegisterConvertible<T>(Func<T, byte[]> converter)
where T : IConvertible
Parameters
Type | Name | Description |
---|---|---|
Func<T, Byte[]> | converter | The function delegate that converts an IConvertible implementation to its equivalent byte[]. |
Type Parameters
Name | Description |
---|---|
T | The type of the IConvertible implementation to use. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ReverseBits16(UInt16)
Reverse the bits of the specified input
.
Declaration
public static ushort ReverseBits16(ushort input)
Parameters
Type | Name | Description |
---|---|---|
UInt16 | input | The unsigned 16-bit integer to reverse bits on. |
Returns
Type | Description |
---|---|
UInt16 | A UInt16 with the bits reversed. |
ReverseBits32(UInt32)
Reverse the bits of the specified input
.
Declaration
public static uint ReverseBits32(uint input)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | input | The unsigned 32-bit integer to reverse bits on. |
Returns
Type | Description |
---|---|
UInt32 | A UInt32 with the bits reversed. |
ReverseBits64(UInt64)
Reverse the bits of the specified input
.
Declaration
public static ulong ReverseBits64(ulong input)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | input | The unsigned 64-bit integer to reverse bits on. |
Returns
Type | Description |
---|---|
UInt64 | A UInt64 with the bits reversed. |
ReverseBits8(Byte)
Reverse the bits of the specified input
.
Declaration
public static byte ReverseBits8(byte input)
Parameters
Type | Name | Description |
---|---|---|
Byte | input | The unsigned 8-bit integer to reverse bits on. |
Returns
Type | Description |
---|---|
Byte | A Byte with the bits reversed. |
ReverseEndianness(Byte[], Action<EndianOptions>)
Reverse the endianness of the specified input
.
Declaration
public static byte[] ReverseEndianness(byte[] input, Action<EndianOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | input | The byte[] to reverse. |
Action<EndianOptions> | setup | The EndianOptions which may be configured. |
Returns
Type | Description |
---|---|
Byte[] | A byte[] that, depending on the |
ToString(Byte[], Action<EncodingOptions>)
Returns the specified byte[] as its equivalent String representation.
Declaration
public static string ToString(byte[] input, Action<EncodingOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | input | The byte[] to convert. |
Action<EncodingOptions> | setup | The EncodingOptions which may be configured. |
Returns
Type | Description |
---|---|
String | A String that is equivalent to |
Remarks
IEncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidEnumArgumentException |
|