System.Memory.Data 9.0.0-rc.2.24473.5

About

System.Memory.Data introduces the BinaryData type, a lightweight abstraction for a byte payload. It makes it easy to convert between string, bytes, and stream.

This abstraction can simplify the API surface by exposing a single type instead of numerous overloads or properties. The BinaryData type handles data ownership efficiently, wrapping passed-in bytes when using byte[] or ReadOnlyMemory<byte> constructors or methods, and managing data as bytes when dealing with streams, strings, or rich model types serialized as JSON.

Key Features

  • Lightweight abstraction for byte payload via BinaryData type.
  • Convenient helper methods for common conversions among string, bytes, and stream.
  • Efficient data ownership handling.

How to Use

To/From String:

var data = new BinaryData("some data");

// ToString will decode the bytes using UTF-8
Console.WriteLine(data.ToString()); // prints "some data"

To/From Bytes:

byte[] bytes = Encoding.UTF8.GetBytes("some data");

// Create BinaryData using a constructor ...
BinaryData data = new BinaryData(bytes);

// Or using a static factory method.
data = BinaryData.FromBytes(bytes);

// There is an implicit cast defined for ReadOnlyMemory<byte>
ReadOnlyMemory<byte> rom = data;

// There is also an implicit cast defined for ReadOnlySpan<byte>
ReadOnlySpan<byte> ros = data;

// there is also a ToMemory method that gives access to the ReadOnlyMemory.
rom = data.ToMemory();

// and a ToArray method that converts into a byte array.
byte[] array = data.ToArray();

To/From stream:

var bytes = Encoding.UTF8.GetBytes("some data");
Stream stream = new MemoryStream(bytes);
var data = BinaryData.FromStream(stream);

// Calling ToStream will give back a stream that is backed by ReadOnlyMemory, so it is not writable.
stream = data.ToStream();
Console.WriteLine(stream.CanWrite); // prints false

BinaryData also can be used to integrate with ObjectSerializer. By default, the JsonObjectSerializer will be used, but any serializer deriving from ObjectSerializer can be used.

var model = new CustomModel
{
    A = "some text",
    B = 5,
    C = true
};

var data = BinaryData.FromObjectAsJson(model);
model = data.ToObjectFromJson<CustomModel>();

Main Types

The main types provided by this library are:

  • System.BinaryData

Additional Documentation

Feedback & Contributing

System.Memory.Data is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Showing the top 20 packages that depend on System.Memory.Data.

Packages Downloads
Azure.Core
This is the implementation of the Azure Client Pipeline
175
Azure.Core
This is the implementation of the Azure Client Pipeline
177
Azure.Core
This is the implementation of the Azure Client Pipeline
179
Azure.Core
This is the implementation of the Azure Client Pipeline
180
Azure.Core
This is the implementation of the Azure Client Pipeline
187
Azure.Core
This is the implementation of the Azure Client Pipeline
188
Azure.Core
This is the implementation of the Azure Client Pipeline
189
Azure.Core
This is the implementation of the Azure Client Pipeline
192
Azure.Core
This is the implementation of the Azure Client Pipeline
194
Azure.Core
This is the implementation of the Azure Client Pipeline
197
Azure.Core
This is the implementation of the Azure Client Pipeline
201
Azure.Core
This is the implementation of the Azure Client Pipeline
202
Azure.Core
This is the implementation of the Azure Client Pipeline
208
Azure.Core
This is the implementation of the Azure Client Pipeline
210

https://go.microsoft.com/fwlink/?LinkID=799421

.NET Framework 4.6.2

.NET 8.0

.NET 9.0

  • No dependencies.

.NET Standard 2.0

Version Downloads Last updated
11.0.0-rc.2.26504.105 0 10/13/2026
11.0.0-rc.1.26425.128 10 09/10/2026
11.0.0-preview.7.26381.103 24 08/12/2026
11.0.0-preview.6.26359.118 31 07/16/2026
11.0.0-preview.5.26302.115 34 06/10/2026
11.0.0-preview.4.26230.115 44 05/13/2026
11.0.0-preview.3.26207.106 53 04/14/2026
11.0.0-preview.2.26159.112 59 03/12/2026
11.0.0-preview.1.26104.118 61 02/11/2026
10.0.13 0 10/13/2026
10.0.12 11 09/10/2026
10.0.11 21 08/12/2026
10.0.10 22 07/16/2026
10.0.9 30 06/10/2026
10.0.8 32 05/13/2026
10.0.7 48 04/21/2026
10.0.6 49 04/14/2026
10.0.5 49 03/13/2026
10.0.4 52 03/12/2026
10.0.3 60 02/11/2026
10.0.2 58 01/13/2026
10.0.1 73 12/10/2025
10.0.0 103 11/12/2025
10.0.0-rc.2.25502.107 92 10/15/2025
10.0.0-rc.1.25451.107 100 09/09/2025
10.0.0-preview.7.25380.108 135 08/13/2025
10.0.0-preview.6.25358.103 129 07/17/2025
10.0.0-preview.5.25277.114 114 06/08/2025
10.0.0-preview.4.25258.110 139 05/13/2025
10.0.0-preview.3.25171.5 150 04/11/2025
10.0.0-preview.2.25163.2 128 04/02/2025
10.0.0-preview.1.25080.5 117 04/02/2025
9.0.21 0 10/13/2026
9.0.20 11 09/11/2026
9.0.19 20 08/11/2026
9.0.18 20 07/16/2026
9.0.17 29 06/10/2026
9.0.16 34 05/13/2026
9.0.15 49 04/15/2026
9.0.14 55 03/12/2026
9.0.13 51 02/11/2026
9.0.12 62 01/15/2026
9.0.11 112 11/12/2025
9.0.10 98 10/15/2025
9.0.9 103 09/09/2025
9.0.8 111 08/06/2025
9.0.7 120 07/09/2025
9.0.6 104 06/11/2025
9.0.5 140 05/14/2025
9.0.4 160 04/11/2025
9.0.3 153 04/01/2025
9.0.2 135 04/01/2025
9.0.1 129 04/01/2025
9.0.0 124 11/17/2024
9.0.0-rc.2.24473.5 142 10/22/2024
9.0.0-rc.1.24431.7 118 09/19/2024
9.0.0-preview.7.24405.7 133 08/22/2024
9.0.0-preview.6.24327.7 150 07/19/2024
9.0.0-preview.5.24306.7 179 07/19/2024
9.0.0-preview.4.24266.19 152 07/19/2024
9.0.0-preview.3.24172.9 173 07/19/2024
9.0.0-preview.2.24128.5 157 07/19/2024
9.0.0-preview.1.24080.9 154 07/19/2024
8.0.1 159 10/21/2024
8.0.0 167 07/19/2024
8.0.0-rc.2.23479.6 138 07/19/2024
8.0.0-rc.1.23419.4 144 07/19/2024
8.0.0-preview.7.23375.6 169 07/19/2024
8.0.0-preview.6.23329.7 152 07/19/2024
8.0.0-preview.5.23280.8 150 07/19/2024
8.0.0-preview.4.23259.5 173 07/19/2024
8.0.0-preview.3.23174.8 161 07/19/2024
8.0.0-preview.2.23128.3 157 07/19/2024
8.0.0-preview.1.23110.8 143 07/19/2024
7.0.0 139 07/19/2024
7.0.0-rc.2.22472.3 146 07/19/2024
7.0.0-rc.1.22426.10 132 07/19/2024
7.0.0-preview.7.22375.6 154 07/19/2024
7.0.0-preview.6.22324.4 158 07/19/2024
7.0.0-preview.5.22301.12 179 07/19/2024
7.0.0-preview.4.22229.4 156 07/19/2024
7.0.0-preview.3.22175.4 158 07/19/2024
7.0.0-preview.2.22152.2 159 07/19/2024
7.0.0-preview.1.22076.8 141 07/19/2024
6.0.1 136 11/17/2024
6.0.0 145 07/19/2024
6.0.0-rc.2.21480.5 144 07/19/2024
6.0.0-rc.1.21451.13 157 07/19/2024
6.0.0-preview.7.21377.19 151 07/19/2024
6.0.0-preview.6.21352.12 149 07/19/2024
6.0.0-preview.5.21301.5 158 07/19/2024
6.0.0-preview.4.21253.7 149 07/19/2024
6.0.0-preview.3.21201.4 164 07/19/2024
6.0.0-preview.2.21154.6 138 07/19/2024
6.0.0-preview.1.21102.12 156 07/19/2024
1.0.2 182 02/04/2024
1.0.1 144 07/19/2024
1.0.0 155 07/19/2024
1.0.0-beta.2 138 07/19/2024
1.0.0-beta.1 139 07/19/2024