GetBytes Method
Definition
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
inputIConvertibleThe value to convert.
setupAction<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
inputis of a type for which no converter has been registered or configured.
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
inputIEnumerable<IConvertible>The sequence of values to convert.
setupAction<ConvertibleOptions>The delegate that configures the conversion options.
Returns
- byte[]
A byte array containing the concatenated byte representations of the elements in
input.
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
inputboolThe value to convert.
setupAction<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
inputbyteThe value to convert.
setupAction<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
inputcharThe value to convert.
setupAction<EndianOptions>The delegate that configures the byte order.
Returns
- byte[]
A byte array that represents
input.
GetBytes(DateTime)
Converts the specified DateTime value to its byte array representation.
public static byte[] GetBytes(DateTime input)
Parameters
inputDateTimeThe 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(DBNull)
Converts the specified DBNull value to its byte array representation.
public static byte[] GetBytes(DBNull input)
Parameters
inputDBNullThe value to convert.
Returns
GetBytes(decimal)
Converts the specified decimal value to its byte array representation.
public static byte[] GetBytes(decimal input)
Parameters
inputdecimalThe 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
inputdoubleThe value to convert.
setupAction<EndianOptions>The delegate that configures the byte order.
Returns
- byte[]
A byte array that represents
input.
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
inputshortThe value to convert.
setupAction<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
inputintThe value to convert.
setupAction<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
inputlongThe value to convert.
setupAction<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
inputsbyteThe value to convert.
setupAction<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
inputfloatThe value to convert.
setupAction<EndianOptions>The delegate that configures the byte order.
Returns
- byte[]
A byte array that represents
input.
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
inputushortThe value to convert.
setupAction<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
inputuintThe value to convert.
setupAction<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
inputulongThe value to convert.
setupAction<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
inputstringThe value to convert.
setupAction<EncodingOptions>The delegate that configures the encoding behavior.
Returns
- byte[]
A byte array that represents
input.
Remarks
EncodingOptions is initialized with DefaultPreambleSequence and DefaultEncoding.
Exceptions
- ArgumentNullException
inputis null.- InvalidEnumArgumentException
setupconfigures an invalid value for Preamble.
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
inputEnumThe value to convert.
setupAction<EndianOptions>The delegate that configures the byte order.
Returns
- byte[]
A byte array that represents the underlying numeric value of
input.