A lightweight abstraction for a payload of bytes that supports converting between string, stream, JSON, and bytes.
Inheritance
BinaryData
Namespace: System
Assembly: System.Memory.Data.dll
Syntax
public class BinaryDataConstructors
BinaryData(Byte[])
Creates a BinaryData instance by wrapping the provided byte array.
Declaration
public BinaryData (byte[] data);Parameters
| Byte[] data The array to wrap. |
BinaryData(ReadOnlyMemory<Byte>)
Creates a BinaryData instance by wrapping the provided bytes.
Declaration
public BinaryData (ReadOnlyMemory<byte> data);Parameters
BinaryData(String)
Creates a BinaryData instance from a string by converting the string to bytes using the UTF-8 encoding.
Declaration
public BinaryData (string data);Parameters
BinaryData(Object, JsonSerializerOptions, Type)
Declaration
public BinaryData (object jsonSerializable, System.Text.Json.JsonSerializerOptions options = null, Type type = null);Parameters
| Object jsonSerializable The object that will be serialized to JSON using JsonSerializer. |
| JsonSerializerOptions options The options to use when serializing to JSON. |
| Type type The type to use when serializing the data. If not specified, GetType() will be used to determine the type. |
Methods
Equals(Object)
Determines whether the specified object is equal to the current object.
Declaration
[System.ComponentModel.EditorBrowsable] public override bool Equals (object obj);Parameters
| Object obj The object to compare with the current object. |
Returns
| Boolean
|
FromBytes(Byte[])
Creates a BinaryData instance by wrapping the provided byte array.
Declaration
public static BinaryData FromBytes (byte[] data);Parameters
| Byte[] data The array to wrap. |
Returns
FromBytes(ReadOnlyMemory<Byte>)
Declaration
public static BinaryData FromBytes (ReadOnlyMemory<byte> data);Parameters
Returns
FromObjectAsJson<T>(T, JsonSerializerOptions)
Declaration
public static BinaryData FromObjectAsJson<T> (T jsonSerializable, System.Text.Json.JsonSerializerOptions options = null);Parameters
| T jsonSerializable The data to use. |
| JsonSerializerOptions options The options to use when serializing to JSON. |
Returns
| BinaryData A value representing the UTF-8 encoding of the JSON representation of |
Type Parameters
| T The type to use when serializing the data. |
FromStream(Stream)
Creates a BinaryData instance from the specified stream. The stream is not disposed by this method.
Declaration
public static BinaryData FromStream (System.IO.Stream stream);Parameters
| Stream stream Stream containing the data. |
Returns
| BinaryData A value representing all of the data remaining in |
FromStreamAsync(Stream, CancellationToken)
Creates a BinaryData instance from the specified stream. The stream is not disposed by this method.
Declaration
public static System.Threading.Tasks.Task<BinaryData> FromStreamAsync (System.IO.Stream stream, System.Threading.CancellationToken cancellationToken = null);Parameters
| Stream stream Stream containing the data. |
| CancellationToken cancellationToken A token that may be used to cancel the operation. |
Returns
| Task<BinaryData> A value representing all of the data remaining in |
FromString(String)
Creates a BinaryData instance from a string by converting the string to bytes using the UTF-8 encoding.
Declaration
public static BinaryData FromString (string data);Parameters
Returns
| BinaryData A value representing the UTF-8 encoding of |
GetHashCode()
Declaration
[System.ComponentModel.EditorBrowsable] public override int GetHashCode ();Returns
ToArray()
Declaration
public byte[] ToArray ();Returns
| Byte[] A byte array representing the data. |
ToMemory()
Gets the value of this instance as bytes without any further interpretation.
Declaration
public ReadOnlyMemory<byte> ToMemory ();Returns
| ReadOnlyMemory<Byte> The value of this instance as bytes without any further interpretation. |
ToObjectFromJson<T>(JsonSerializerOptions)
Declaration
public T ToObjectFromJson<T> (System.Text.Json.JsonSerializerOptions options = null);Parameters
Returns
| T The data converted to the specified type. |
Type Parameters
| T The type that the data should be converted to. |
ToStream()
Declaration
public System.IO.Stream ToStream ();Returns
| Stream A stream representing the data. |
ToString()
Converts the value of this instance to a string using UTF-8.
Declaration
public override string ToString ();Returns
| String A string from the value of this instance, using UTF-8 to decode the bytes. |
Operators
Implicit(BinaryData to ReadOnlyMemory<Byte>)
Declaration
public static implicit operator ReadOnlyMemory<byte> (BinaryData data);Parameters
Returns
Implicit(BinaryData to ReadOnlySpan<Byte>)
Declaration
public static implicit operator ReadOnlySpan<byte> (BinaryData data);Parameters
Returns
ncG1vNJzZmiZqqq%2Fpr%2FDpJuom6Njr627wWeaqKqVY8SqusOorqxmnprBcHDWnplonJ%2Bpu6bAjoywrKyVonuOscyoqbJmdJbBonuQZ2dnaV%2BWvap7srKqrZ2dZKC6v9OepGd6maOus8WjmquaZpipuq0%3D