Table of Contents

Delegate Utf8JsonWriterAction<T>

Namespace
Cuemon.Extensions.Text.Json
Assembly
Cuemon.Extensions.Text.Json.dll

Represents the Write method of JsonConverter<T>.

public delegate void Utf8JsonWriterAction<in T>(Utf8JsonWriter writer, T value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The Utf8JsonWriter to write to.

value T

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.

Type Parameters

T

The type of object or value handled by the converter.

Extension Methods

Examples

The following example demonstrates how a can serialize a value inside a dynamic JSON converter.

using System;
using System.Text.Json;
using Cuemon.Extensions.Text.Json;

namespace MyApp.Examples;

public static class Utf8JsonWriterActionExample
{
    public static void Demonstrate()
    {
        Utf8JsonWriterAction<Guid> writer = (jsonWriter, value, _) =>
            jsonWriter.WriteStringValue(value.ToString("D"));

        var converter = DynamicJsonConverter.Create<Guid>(writer: writer);
        var json = JsonSerializer.Serialize(Guid.Parse("11111111-2222-3333-4444-555555555555"), new JsonSerializerOptions
        {
            Converters = { converter }
        });

        Console.WriteLine(json);
    }
}