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
<PackageReference Include="OutWit.Common.MemoryPack" Version="1.0.1" />
<PackageVersion Include="OutWit.Common.MemoryPack" Version="1.0.1" />
<PackageReference Include="OutWit.Common.MemoryPack" />
paket add OutWit.Common.MemoryPack --version 1.0.1
#r "nuget: OutWit.Common.MemoryPack, 1.0.1"
#:package OutWit.Common.MemoryPack@1.0.1
#addin nuget:?package=OutWit.Common.MemoryPack&version=1.0.1
#tool nuget:?package=OutWit.Common.MemoryPack&version=1.0.1
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 forSystem.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>
andMemoryPackSet<TValue>
for serializable, read-only collections. - Messaging:
MemoryPackMessage
andMemoryPackMessageWith<TData>
for creating standardized DTOs. - Domain Primitives: Includes
MemoryPackRange<TValue>
,MemoryPackRangeSet<TValue>
, andMemoryPackValueInSet<TValue>
for representing common data constraints.
- Collections:
- 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 | Versions 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. |
-
net6.0
- MemoryPack (>= 1.21.4)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- OutWit.Common.Aspects (>= 1.2.2)
-
net7.0
- MemoryPack (>= 1.21.4)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- OutWit.Common.Aspects (>= 1.2.2)
-
net8.0
- MemoryPack (>= 1.21.4)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- OutWit.Common.Aspects (>= 1.2.2)
-
net9.0
- MemoryPack (>= 1.21.4)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- OutWit.Common.Aspects (>= 1.2.2)
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.