System.Memory.Data 9.0.4

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package System.Memory.Data --version 9.0.4
                    
NuGet\Install-Package System.Memory.Data -Version 9.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="System.Memory.Data" Version="9.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="System.Memory.Data" Version="9.0.4" />
                    
Directory.Packages.props
<PackageReference Include="System.Memory.Data" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add System.Memory.Data --version 9.0.4
                    
#r "nuget: System.Memory.Data, 9.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=System.Memory.Data&version=9.0.4
                    
Install System.Memory.Data as a Cake Addin
#tool nuget:?package=System.Memory.Data&version=9.0.4
                    
Install System.Memory.Data as a Cake Tool

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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (165)

Showing the top 5 NuGet packages that depend on System.Memory.Data:

Package Downloads
Azure.Core

This is the implementation of the Azure Client Pipeline

Microsoft.Azure.WebJobs

This package contains the runtime host components of the WebJobs SDK. For more information, please visit https://go.microsoft.com/fwlink/?linkid=2279708.

Microsoft.Azure.WebJobs.Core

This package provides the core Types and Attribute definitions for the WebJobs SDK. For more information, please visit https://go.microsoft.com/fwlink/?linkid=2279708.

System.ClientModel

Contains building blocks for clients that call cloud services.

Azure.Core.Amqp

This library contains AMQP model types used by Azure libraries.

GitHub repositories (34)

Showing the top 20 popular GitHub repositories that depend on System.Memory.Data:

Repository Stars
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
dotnet/orleans
Cloud Native application framework for .NET
Azure/azure-sdk-for-net
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
dotnet/extensions
This repository contains a suite of libraries that provide facilities commonly needed when creating production-ready applications.
SciSharp/BotSharp
AI Multi-Agent Framework in .NET
Azure/azure-functions-host
The host/runtime that powers Azure Functions
microsoft/kernel-memory
RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.
smartstore/Smartstore
A modular, scalable and ultra-fast open-source all-in-one eCommerce platform built on ASP.NET Core 7
MarimerLLC/csla
A home for your business logic in any .NET application.
optimajet/WorkflowEngine.NET
WorkflowEngine.NET - component that adds workflow in your application. It can be fully integrated into your application, or be in the form of a specific service (such as a web service).
tryAGI/LangChain
C# implementation of LangChain. We try to be as close to the original as possible in terms of abstractions, but are open to new entities.
Azure/azure-webjobs-sdk
Azure WebJobs SDK
Kyrodan/KeeAnywhere
A cloud storage provider plugin for KeePass Password Safe
SparkDevNetwork/Rock
An open source CMS, Relationship Management System (RMS) and Church Management System (ChMS) all rolled into one.
OpenRakis/Spice86
Reverse engineer and rewrite real mode DOS programs!
Avanade/Liquid-Application-Framework
Liquid Application Framework documentation, useful links and sample project
microsoft/SqlNexus
SQL Nexus is a tool that helps you identify the root cause of SQL Server performance issues. It loads and analyzes performance data collected by SQL LogScout, SQLDiag or PSSDiag. It can dramatically reduce the amount of time you spend manually analyzing data.
0xced/Chisel
Remove unwanted dependencies from your dotnet projects
OData/ODataSamples
Samples: For ODataLib, OData Web API, RESTier, etc.
trimble-oss/dba-dash
DBA Dash - SQL Server Monitoring Tool
Version Downloads Last updated
10.0.0-preview.3.25171.5 587 13 days ago
10.0.0-preview.2.25163.2 1,086 a month ago
10.0.0-preview.1.25080.5 1,404 2 months ago
9.0.4 41,298 15 days ago
9.0.3 163,441 a month ago
9.0.2 261,460 2 months ago
9.0.1 321,620 3 months ago
9.0.0 692,171 5 months ago
9.0.0-rc.2.24473.5 7,197 6 months ago
9.0.0-rc.1.24431.7 15,217 7 months ago
9.0.0-preview.7.24405.7 1,706 8 months ago
9.0.0-preview.6.24327.7 2,197 9 months ago
9.0.0-preview.5.24306.7 3,349 6/11/2024
9.0.0-preview.4.24266.19 1,083 5/21/2024
9.0.0-preview.3.24172.9 1,280 4/11/2024
9.0.0-preview.2.24128.5 2,580 3/12/2024
9.0.0-preview.1.24080.9 1,111 2/13/2024
8.0.1 1,902,224 6 months ago
8.0.0 5,836,855 11/14/2023
8.0.0-rc.2.23479.6 4,787 10/10/2023
8.0.0-rc.1.23419.4 5,151 9/12/2023
8.0.0-preview.7.23375.6 5,573 8/8/2023
8.0.0-preview.6.23329.7 3,850 7/11/2023
8.0.0-preview.5.23280.8 1,773 6/13/2023
8.0.0-preview.4.23259.5 836 5/16/2023
8.0.0-preview.3.23174.8 3,681 4/11/2023
8.0.0-preview.2.23128.3 1,350 3/14/2023
8.0.0-preview.1.23110.8 25,950 2/21/2023
7.0.0 5,492,011 11/7/2022
7.0.0-rc.2.22472.3 12,063 10/11/2022
7.0.0-rc.1.22426.10 2,724 9/14/2022
7.0.0-preview.7.22375.6 3,226 8/9/2022
7.0.0-preview.6.22324.4 886 7/12/2022
7.0.0-preview.5.22301.12 1,044 6/14/2022
7.0.0-preview.4.22229.4 2,038 5/10/2022
7.0.0-preview.3.22175.4 1,206 4/13/2022
7.0.0-preview.2.22152.2 873 3/14/2022
7.0.0-preview.1.22076.8 3,770 2/17/2022
6.0.1 637,451 5 months ago
6.0.0 54,376,625 11/8/2021
6.0.0-rc.2.21480.5 1,047 10/12/2021
6.0.0-rc.1.21451.13 2,291 9/14/2021
6.0.0-preview.7.21377.19 3,061 8/10/2021
6.0.0-preview.6.21352.12 1,860 7/14/2021
6.0.0-preview.5.21301.5 841 6/15/2021
6.0.0-preview.4.21253.7 11,831 5/24/2021
6.0.0-preview.3.21201.4 1,392 4/8/2021
6.0.0-preview.2.21154.6 1,076 3/11/2021
6.0.0-preview.1.21102.12 2,072 2/12/2021
1.0.2 565,351,844 4/8/2021
1.0.1 104,375,833 11/16/2020
1.0.0 2,361,210 11/4/2020
1.0.0-beta.2 633 11/4/2020
1.0.0-beta.1 684 11/3/2020