JsonSerializerOptions.AddContext<TContext> 方法

定義

警告

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

將新的 JsonSerializerContext 附加至目前 JsonSerializerOptions 實例的中繼資料解析。

public:
generic <typename TContext>
 where TContext : System::Text::Json::Serialization::JsonSerializerContextgcnew() void AddContext();
[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();
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}")>]
member this.AddContext : unit -> unit (requires 'Context :> System.Text.Json.Serialization.JsonSerializerContext and 'Context : (new : unit -> 'Context))
member this.AddContext : unit -> unit (requires 'Context :> System.Text.Json.Serialization.JsonSerializerContext and 'Context : (new : unit -> 'Context))
Public Sub AddContext(Of TContext As {JsonSerializerContextNew}) ()

類型參數

TContext

指定之內容型別的泛型定義。

屬性

備註

使用選項實例序列化和還原序列化型別時,將會從內容實例擷取型別的中繼資料。

方法支援為每個選項實例新增多個內容。 中繼資料會依組態順序解析,類似于解析中繼資料的方式 Combine(IJsonTypeInfoResolver[])

適用於