Class ByteConverter
This utility class is designed to make System.Byte related conversions easier to work with.
Inheritance
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class ByteConverter
Methods
| Improve this DocFromConvertibles<T>(T)
Converts the specified value
to an array of bytes.
Declaration
public static byte[] FromConvertibles<T>(T value)
where T : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
T | value | The System.IConvertible value to convert. |
Returns
Type | Description |
---|---|
System.Byte[] | An array of bytes equivalent to the data of the |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
|
FromConvertibles<T>(IEnumerable<T>)
Converts the specified sequence of values
to an array of bytes.
Declaration
public static byte[] FromConvertibles<T>(IEnumerable<T> values)
where T : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | values | A sequence of System.IConvertible values to convert. |
Returns
Type | Description |
---|---|
System.Byte[] | An array of bytes equivalent to the sequence of the |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
|
System.ArgumentNullException |
|
FromStream(Stream)
Converts the specified value
to a byte array always starting from position 0 (when supported).
Declaration
public static byte[] FromStream(Stream value)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | value | The System.IO.Stream value to be converted. |
Returns
Type | Description |
---|---|
System.Byte[] | A byte array containing the data from the stream. |
FromStream(Stream, Boolean)
Converts the specified value
to a byte array.
Declaration
public static byte[] FromStream(Stream value, bool leaveStreamOpen)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | value | The System.IO.Stream value to be converted. |
System.Boolean | leaveStreamOpen | if |
Returns
Type | Description |
---|---|
System.Byte[] | A byte array containing the data from the stream. |
FromString(String, Action<EncodingOptions>)
Converts the specified value
to a byte array using the provided preferred encoding.
Declaration
public static byte[] FromString(string value, Action<EncodingOptions> setup = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The string to be converted. |
System.Action<EncodingOptions> | setup | The EncodingOptions which need to be configured. |
Returns
Type | Description |
---|---|
System.Byte[] | A byte array which is the result of the specified delegate |
Remarks
EncodingOptions will be initialized with DefaultPreambleSequence and DefaultEncoding.
FromUrlEncodedBase64(String)
Decodes a URL string token to its equivalent byte array using base 64 digits.
Declaration
public static byte[] FromUrlEncodedBase64(string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The URL string token to decode. |
Returns
Type | Description |
---|---|
System.Byte[] | The byte array containing the decoded URL string token. |
Remarks
| Improve this DocTryFromBase64String(String, out Byte[])
Converts the string representation of a Base64 to its equivalent byte[] array.
Declaration
public static bool TryFromBase64String(string value, out byte[] result)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The Base64 to convert. |
System.Byte[] | result | The array that will contain the parsed value. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Remarks
This method returns false
if value
is null
, empty
or not in a recognized format, and does not throw an exception.
result
will have a default value of null
.
TryFromBase64String(String, Func<String, Boolean>, out Byte[])
Converts the string representation of a Base64 to its equivalent byte[] array.
Declaration
public static bool TryFromBase64String(string value, Func<string, bool> predicate, out byte[] result)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The Base64 to convert. |
System.Func<System.String, System.Boolean> | predicate | A function delegate that provides custom rules for bypassing the Base64 structure check. |
System.Byte[] | result | The array that will contain the parsed value. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Remarks
This method returns false
if value
is null
, empty
or not in a recognized format, and does not throw an exception.
result
will have a default value of null
.