Table of Contents

Delegate Utf8JsonReaderFunc<T>

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

Represents the Read method of JsonConverter<T>.

public delegate T Utf8JsonReaderFunc<out T>(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Parameters

reader Utf8JsonReader

The Utf8JsonReader to read from.

typeToConvert Type

The type to convert.

options JsonSerializerOptions

An object that specifies serialization options to use.

Returns

T

The converted value.

Type Parameters

T

The type of object or value handled by the converter.

Extension Methods

Examples

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

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

namespace MyApp.Examples;

public static class Utf8JsonReaderFuncExample
{
    public static void Demonstrate()
    {
        Utf8JsonReaderFunc<Guid> reader = (ref Utf8JsonReader jsonReader, Type _, JsonSerializerOptions __) =>
            Guid.Parse(jsonReader.GetString());

        var converter = DynamicJsonConverter.Create<Guid>(reader: reader);
        var result = JsonSerializer.Deserialize<Guid>("\"11111111-2222-3333-4444-555555555555\"", new JsonSerializerOptions
        {
            Converters = { converter }
        });

        Console.WriteLine(result);
    }
}