PolyType.Examples
1.0.0-rc.9
See the version list below for details.
dotnet add package PolyType.Examples --version 1.0.0-rc.9
NuGet\Install-Package PolyType.Examples -Version 1.0.0-rc.9
<PackageReference Include="PolyType.Examples" Version="1.0.0-rc.9" />
<PackageVersion Include="PolyType.Examples" Version="1.0.0-rc.9" />
<PackageReference Include="PolyType.Examples" />
paket add PolyType.Examples --version 1.0.0-rc.9
#r "nuget: PolyType.Examples, 1.0.0-rc.9"
#:package PolyType.Examples@1.0.0-rc.9
#addin nuget:?package=PolyType.Examples&version=1.0.0-rc.9&prerelease
#tool nuget:?package=PolyType.Examples&version=1.0.0-rc.9&prerelease
PolyType.Examples
Includes a set of reference library implementations built on top of the PolyType abstractions. These include:
- A serializer built on top of System.Text.Json,
- A serializer built on top of System.Xml,
- A serializer built on top of System.Formats.Cbor,
- A
ConfigurationBinderlike implementation, - A dependency injection implementation,
- A simple pretty-printer for .NET values,
- A generic random value generator based on
System.Random, - A JSON schema generator for .NET types,
- An object graph cloning function,
- A structural
IEqualityComparer<T>generator for POCOs and collections, - An object validator in the style of System.ComponentModel.DataAnnotations.
- A simple .NET object mapper.
RPC Generation with JsonFunc
The JSON serializer includes JsonFunc and JsonEvent abstractions that enable rapid development of RPC systems. These wrap .NET methods with JSON-based parameter marshaling, making it easy to build HTTP APIs, message-based RPC, or any dynamic invocation scenario.
JsonFunc Example
using PolyType;
using PolyType.Examples.JsonSerializer;
[GenerateShape, TypeShape(IncludeMethods = MethodShapeFlags.PublicInstance)]
public partial class ApiService
{
public async ValueTask<string> GreetAsync(string name)
{
await Task.Delay(10);
return $"Hello, {name}!";
}
}
var service = new ApiService();
var serviceShape = TypeShapeResolver.Resolve<ApiService>();
var greetMethod = serviceShape.Methods.First(m => m.Name == "GreetAsync");
// Create a JSON-based delegate
var jsonFunc = JsonSerializerTS.CreateJsonFunc(greetMethod, service);
// Invoke with JSON parameters
var result = await jsonFunc.Invoke("""{"name": "World"}""");
Console.WriteLine(result.GetRawText()); // "Hello, World!"
JsonEvent Example
Event shapes can be wrapped with JsonEvent for dynamic event handling:
[GenerateShape, TypeShape(IncludeMethods = MethodShapeFlags.PublicInstance)]
public partial class NotificationService
{
public event AsyncEventHandler<string>? OnNotification;
public async ValueTask SendNotificationAsync(string message)
{
if (OnNotification != null)
{
await OnNotification(this, message, CancellationToken.None);
}
}
}
var service = new NotificationService();
var serviceShape = TypeShapeResolver.Resolve<NotificationService>();
var onNotificationEvent = serviceShape.Events.First(e => e.Name == "OnNotification");
var jsonEvent = JsonSerializerTS.CreateAsyncJsonEvent(onNotificationEvent, service);
jsonEvent.Subscribe(async (sender, parameters, ct) =>
{
Console.WriteLine($"Received: {parameters["message"]}");
return JsonDocument.Parse("{}").RootElement;
});
These abstractions demonstrate how PolyType's method and event shapes enable building complete RPC frameworks with minimal code.
| Product | Versions 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. net10.0 is compatible. 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 | 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 was computed. 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. |
-
.NETStandard 2.0
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Microsoft.Extensions.Configuration (>= 9.0.8)
- PolyType (>= 1.0.0-rc.9)
- System.Formats.Cbor (>= 9.0.8)
- System.Memory (>= 4.5.5)
- System.Reflection.Emit.Lightweight (>= 4.7.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
- System.Text.Json (>= 9.0.8)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
net10.0
- Microsoft.Extensions.Configuration (>= 9.0.8)
- PolyType (>= 1.0.0-rc.9)
- System.Formats.Cbor (>= 9.0.8)
-
net8.0
- Microsoft.Extensions.Configuration (>= 9.0.8)
- PolyType (>= 1.0.0-rc.9)
- System.Formats.Cbor (>= 9.0.8)
-
net9.0
- Microsoft.Extensions.Configuration (>= 9.0.8)
- PolyType (>= 1.0.0-rc.9)
- System.Formats.Cbor (>= 9.0.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-unstable | 358 | 12/8/2025 |
| 1.0.0-rc.9 | 101 | 11/15/2025 |
| 1.0.0-rc.8 | 167 | 11/14/2025 |
| 1.0.0-rc.7 | 58 | 10/17/2025 |
| 1.0.0-rc.6 | 77 | 10/10/2025 |
| 1.0.0-rc.5 | 130 | 9/29/2025 |
| 1.0.0-rc.4 | 132 | 9/23/2025 |
| 1.0.0-rc.3 | 263 | 9/18/2025 |
| 1.0.0-rc.2 | 265 | 9/16/2025 |
| 1.0.0-rc.1 | 263 | 9/16/2025 |