Table of Contents

Class SchemaSourceGenerationContext

Namespace
GenerativeAI.Types
Assembly
GenerativeAI.dll

The SchemaSourceGenerationContext class is a custom source generation context for improving the performance of JSON serialization and deserialization. This is achieved by leveraging the JsonSourceGenerationOptionsAttribute to configure source generation options and define types for serialization at compile-time.

[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Schema))]
public class SchemaSourceGenerationContext : JsonSerializerContext, IJsonTypeInfoResolver
Inheritance
SchemaSourceGenerationContext
Implements
Inherited Members
Extension Methods

Constructors

SchemaSourceGenerationContext()

public SchemaSourceGenerationContext()

SchemaSourceGenerationContext(JsonSerializerOptions)

Creates an instance of JsonSerializerContext and binds it with the indicated JsonSerializerOptions.

public SchemaSourceGenerationContext(JsonSerializerOptions options)

Parameters

options JsonSerializerOptions

The run time provided options for the context instance.

Properties

Boolean

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<bool> Boolean { get; }

Property Value

JsonTypeInfo<bool>

Default

The default JsonSerializerContext associated with a default JsonSerializerOptions instance.

public static SchemaSourceGenerationContext Default { get; }

Property Value

SchemaSourceGenerationContext

DictionaryStringSchema

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<Dictionary<string, Schema>> DictionaryStringSchema { get; }

Property Value

JsonTypeInfo<Dictionary<string, Schema>>

Double

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<double> Double { get; }

Property Value

JsonTypeInfo<double>

GeneratedSerializerOptions

The source-generated options associated with this context.

protected override JsonSerializerOptions? GeneratedSerializerOptions { get; }

Property Value

JsonSerializerOptions

Int32

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<int> Int32 { get; }

Property Value

JsonTypeInfo<int>

Int64

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<long> Int64 { get; }

Property Value

JsonTypeInfo<long>

JsonNode

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<JsonNode> JsonNode { get; }

Property Value

JsonTypeInfo<JsonNode>

ListSchema

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<List<Schema>> ListSchema { get; }

Property Value

JsonTypeInfo<List<Schema>>

ListString

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<List<string>> ListString { get; }

Property Value

JsonTypeInfo<List<string>>

NullableBoolean

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<bool?> NullableBoolean { get; }

Property Value

JsonTypeInfo<bool?>

NullableDouble

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<double?> NullableDouble { get; }

Property Value

JsonTypeInfo<double?>

NullableInt32

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<int?> NullableInt32 { get; }

Property Value

JsonTypeInfo<int?>

NullableInt64

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<long?> NullableInt64 { get; }

Property Value

JsonTypeInfo<long?>

Schema

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<Schema> Schema { get; }

Property Value

JsonTypeInfo<Schema>

String

Defines the source generated JSON serialization contract metadata for a given type.

public JsonTypeInfo<string> String { get; }

Property Value

JsonTypeInfo<string>

Methods

GetTypeInfo(Type)

Gets metadata for the specified type.

public override JsonTypeInfo? GetTypeInfo(Type type)

Parameters

type Type

The type to fetch metadata for.

Returns

JsonTypeInfo

The metadata for the specified type, or null if the context has no metadata for the type.

See Also