AndanteTribe.SerializableFormat.MessagePack
1.0.0
dotnet add package AndanteTribe.SerializableFormat.MessagePack --version 1.0.0
NuGet\Install-Package AndanteTribe.SerializableFormat.MessagePack -Version 1.0.0
<PackageReference Include="AndanteTribe.SerializableFormat.MessagePack" Version="1.0.0" />
<PackageVersion Include="AndanteTribe.SerializableFormat.MessagePack" Version="1.0.0" />
<PackageReference Include="AndanteTribe.SerializableFormat.MessagePack" />
paket add AndanteTribe.SerializableFormat.MessagePack --version 1.0.0
#r "nuget: AndanteTribe.SerializableFormat.MessagePack, 1.0.0"
#:package AndanteTribe.SerializableFormat.MessagePack@1.0.0
#addin nuget:?package=AndanteTribe.SerializableFormat.MessagePack&version=1.0.0
#tool nuget:?package=AndanteTribe.SerializableFormat.MessagePack&version=1.0.0
SerializableFormat
English | 日本語
Overview
SerializableFormat is a .NET library that provides a serializable, .NET Standard 2.1-compatible alternative to .NET 8's System.Text.CompositeFormat.
It provides the following:
SerializableCompositeFormat— Parses a composite format string once and exposes its originalFormatandMinimumArgumentCount.FormatExtensions— Providesstring.Format,StringBuilder.AppendFormat, andSpan<char>.TryWrite-style operations for a parsedSerializableCompositeFormat.SerializableFormat.Json— An optional package that preserves the parsed state withSystem.Text.Json.SerializableFormat.MessagePack— An optional package that preserves the parsed state with MessagePack.
The serialization packages store the parsed segment array and the three derived fields used by the BCL implementation. Deserialization restores that state directly without parsing Format again.
Installation
NuGet Packages
This library requires a target compatible with .NET Standard 2.1 or later. The packages can be obtained from NuGet.
.NET CLI
Core package
dotnet add package AndanteTribe.SerializableFormat
System.Text.Json support (optional)
dotnet add package AndanteTribe.SerializableFormat.Json
MessagePack support (optional)
dotnet add package AndanteTribe.SerializableFormat.MessagePack
Package Manager
Core package
Install-Package AndanteTribe.SerializableFormat
System.Text.Json support (optional)
Install-Package AndanteTribe.SerializableFormat.Json
MessagePack support (optional)
Install-Package AndanteTribe.SerializableFormat.MessagePack
Quick Start
using SerializableFormat;
using System.Globalization;
var format = SerializableCompositeFormat.Parse("Order {0}: {1,10:N2}");
Console.WriteLine(format.Format); // "Order {0}: {1,10:N2}"
Console.WriteLine(format.MinimumArgumentCount); // 2
var text = string.Format(
CultureInfo.InvariantCulture,
format,
42,
123.45m);
Console.WriteLine(text);
SerializableCompositeFormat
SerializableCompositeFormat represents a parsed composite format string. Call Parse once, then reuse the result for formatting or serialization.
Formatreturns the original composite format string.MinimumArgumentCountreturns one more than the largest argument index referenced by the format.Parse(string)supports composite format items, alignment, format specifiers, and escaped braces with behavior compatible with the BCL composite-format parser.
var format = SerializableCompositeFormat.Parse(
"{{Order}} {0}: {1,-12:C2}");
Formatting
The core package provides three families of formatting operations. Each family includes generic overloads for one through seven arguments, plus object?[] and ReadOnlySpan<object?> overloads.
With C# 14, the static extension can be called through string.Format. Calling the containing class directly also works for consumers using older C# versions:
using SerializableFormat;
using System.Globalization;
var format = SerializableCompositeFormat.Parse("Order {0}: {1,10:N2}");
// C# 14 static extension syntax
var text = string.Format(
CultureInfo.InvariantCulture,
format,
42,
123.45m);
// Direct call for older C# versions
var compatibleText = FormatExtensions.Format(
CultureInfo.InvariantCulture,
format,
42,
123.45m);
The same parsed format can be appended to a StringBuilder or written to a destination span:
using System.Text;
var builder = new StringBuilder();
builder.AppendFormat(
CultureInfo.InvariantCulture,
format,
42,
123.45m);
Span<char> destination = stackalloc char[64];
if (destination.TryWrite(
CultureInfo.InvariantCulture,
format,
out var charsWritten,
42,
123.45m))
{
Console.WriteLine(destination[..charsWritten]);
}
All three operation families honor the supplied IFormatProvider, including a custom ICustomFormatter, as well as alignment and format specifiers.
System.Text.Json Support
Register CompositeFormatJsonConverter in the serializer options:
using SerializableFormat;
using SerializableFormat.Json;
using System.Text.Json;
var options = new JsonSerializerOptions();
options.Converters.Add(new CompositeFormatJsonConverter());
var format = SerializableCompositeFormat.Parse("Order {0}: {1,10:N2}");
var json = JsonSerializer.Serialize(format, options);
var restored = JsonSerializer.Deserialize<SerializableCompositeFormat>(json, options)!;
MessagePack Support
CompositeFormatResolver resolves the formatter for SerializableCompositeFormat:
using MessagePack;
using SerializableFormat;
using SerializableFormat.MessagePack;
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeFormatResolver.Instance);
var format = SerializableCompositeFormat.Parse("Order {0}: {1,10:N2}");
var bytes = MessagePackSerializer.Serialize(format, options);
var restored = MessagePackSerializer.Deserialize<SerializableCompositeFormat>(bytes, options);
If the application already uses another resolver, register CompositeFormatMessagePackFormatter.Instance in a composite resolver ahead of the application's existing resolvers.
Serialized State
The JSON representation writes these properties in order: Format, _segments, _literalLength, _formattedCount, and _argsRequired. Each segment is a four-element array containing Literal, ArgIndex, Alignment, and Format.
MessagePack stores the same five top-level values in the same order as an array. Each segment uses the same four-element array representation.
For forward compatibility, the JSON reader ignores unknown object properties and extra values at the end of segment arrays. The MessagePack reader skips trailing values in both top-level and segment arrays.
Deserialization restores all five values directly. It does not reparse Format, recompute derived values, or validate that the fields agree with each other.
License
This library is released under the MIT license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- AndanteTribe.SerializableFormat (>= 1.0.0)
- MessagePack (>= 3.1.8)
-
net6.0
- AndanteTribe.SerializableFormat (>= 1.0.0)
- MessagePack (>= 3.1.8)
-
net7.0
- AndanteTribe.SerializableFormat (>= 1.0.0)
- MessagePack (>= 3.1.8)
-
net8.0
- AndanteTribe.SerializableFormat (>= 1.0.0)
- MessagePack (>= 3.1.8)
-
net9.0
- AndanteTribe.SerializableFormat (>= 1.0.0)
- MessagePack (>= 3.1.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 86 | 9/4/2026 |