OutWit.Common.MemoryPack 1.0.1

dotnet add package OutWit.Common.MemoryPack --version 1.0.1
                    
NuGet\Install-Package OutWit.Common.MemoryPack -Version 1.0.1
                    
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="OutWit.Common.MemoryPack" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OutWit.Common.MemoryPack" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="OutWit.Common.MemoryPack" />
                    
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 OutWit.Common.MemoryPack --version 1.0.1
                    
#r "nuget: OutWit.Common.MemoryPack, 1.0.1"
                    
#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.
#:package OutWit.Common.MemoryPack@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OutWit.Common.MemoryPack&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=OutWit.Common.MemoryPack&version=1.0.1
                    
Install as a Cake Tool

OutWit.Common.MemoryPack

OutWit.Common.MemoryPack is a .NET library that provides a collection of helper methods and pre-configured, serializable types to simplify and accelerate development with the MemoryPack serialization library. It offers extension methods for common tasks, custom formatters, and a suite of ready-to-use data structures for various domain needs.

Key Features

  • Fluent Extension Methods: Simplifies serializing, deserializing, and cloning objects.
  • File I/O Helpers: Easily export and load collections of objects to and from files, both synchronously and asynchronously.
  • Custom Formatter for PropertyChangedEventArgs: Includes a built-in formatter for System.ComponentModel.PropertyChangedEventArgs, which is automatically registered and essential for MVVM applications.
  • Serializable-Ready Types: A collection of [MemoryPackable] types designed to be used directly in your data models:
    • Collections: MemoryPackMap<TKey, TValue> and MemoryPackSet<TValue> for serializable, read-only collections.
    • Messaging: MemoryPackMessage and MemoryPackMessageWith<TData> for creating standardized DTOs.
    • Domain Primitives: Includes MemoryPackRange<TValue>, MemoryPackRangeSet<TValue>, and MemoryPackValueInSet<TValue> for representing common data constraints.
  • Easy Configuration: A simple registration pattern to add your own custom formatters.
  • Cross-Platform Support: Targets .NET 6, 7, 8, and 9.

Installation

Install the package from NuGet using the .NET CLI:

dotnet add package OutWit.Common.MemoryPack

Usage

Basic Serialization and Deserialization

The MemoryPackUtils class provides convenient extension methods.

using OutWit.Common.MemoryPack;
using MemoryPack;

[MemoryPackable]
public partial class User
{
    public string Name { get; set; }
    public int Age { get; set; }
}

var user = new User { Name = "John Doe", Age = 30 };

// Serialize the object to bytes
byte[] bytes = user.ToMemoryPackBytes();

// Deserialize the bytes back to an object
User deserializedUser = bytes.FromMemoryPackBytes<User>();

Cloning an Object

You can easily create a deep clone of any [MemoryPackable] object.

// Clone the user object
[cite_start]User clonedUser = user.MemoryPackClone();

Exporting and Loading Collections

Save a collection to a file and load it back.

using OutWit.Common.MemoryPack.Ranges;

var ranges = new List<MemoryPackRange<int>>
{
    new(1, 10),
    new(20, 30)
};

// Export the list to a file
await ranges.ExportAsMemoryPackAsync("ranges.bin"); 

// Load the list from the file
IReadOnlyList<MemoryPackRange<int>> loadedRanges = await MemoryPackUtils.LoadAsMemoryPackAsync<MemoryPackRange<int>>("ranges.bin");

Registering a Custom Formatter

You can register your own custom MemoryPackFormatter during application startup.

// Your custom formatter
public class MyCustomTypeFormatter : MemoryPackFormatter<MyCustomType>
{
    // ... implementation
}

// Register it
MemoryPackUtils.Register(options => 
{
    options.Register(new MyCustomTypeFormatter());
});
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OutWit.Common.MemoryPack:

Package Downloads
OutWit.Communication

The core communication library of the WitRPC framework, providing base RPC functionality such as messaging, dynamic proxy support, and extensibility for multiple transports, serialization formats, and encryption.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 261 6/29/2025
1.0.0 209 6/6/2025