Bagikan melalui


JsonSerializerOptions.AddContext<TContext> Metode

Definisi

Perhatian

JsonSerializerOptions.AddContext is obsolete. To register a JsonSerializerContext, use either the TypeInfoResolver or TypeInfoResolverChain properties.

Menambahkan baru JsonSerializerContext ke resolusi metadata instans saat ini JsonSerializerOptions .

public:
generic <typename TContext>
 where TContext : System::Text::Json::Serialization::JsonSerializerContextgcnew() void AddContext();
public void AddContext<TContext> () where TContext : System.Text.Json.Serialization.JsonSerializerContext, new();
[System.Obsolete("JsonSerializerOptions.AddContext is obsolete. To register a JsonSerializerContext, use either the TypeInfoResolver or TypeInfoResolverChain properties.", DiagnosticId="SYSLIB0049", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public void AddContext<TContext> () where TContext : System.Text.Json.Serialization.JsonSerializerContext, new();
member this.AddContext : unit -> unit (requires 'Context :> System.Text.Json.Serialization.JsonSerializerContext and 'Context : (new : unit -> 'Context))
[<System.Obsolete("JsonSerializerOptions.AddContext is obsolete. To register a JsonSerializerContext, use either the TypeInfoResolver or TypeInfoResolverChain properties.", DiagnosticId="SYSLIB0049", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
member this.AddContext : unit -> unit (requires 'Context :> System.Text.Json.Serialization.JsonSerializerContext and 'Context : (new : unit -> 'Context))
Public Sub AddContext(Of TContext As {JsonSerializerContextNew}) ()

Jenis parameter

TContext

Definisi generik dari jenis konteks yang ditentukan.

Atribut

Keterangan

Saat menserialisasikan dan mendeserialisasi jenis menggunakan instans opsi, metadata untuk jenis akan diambil dari instans konteks.

Metode ini mendukung penambahan beberapa konteks per instans opsi. Metadata akan diselesaikan dalam urutan konfigurasi, mirip dengan cara Combine(IJsonTypeInfoResolver[]) menyelesaikan metadata.

Berlaku untuk