JsonSerializerOptions.AddContext<TContext> 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
警告
JsonSerializerOptions.AddContext is obsolete. To register a JsonSerializerContext, use either the TypeInfoResolver or TypeInfoResolverChain properties.
在目前JsonSerializerOptions實例的元資料解析中附加一個新JsonSerializerContext內容。
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
指定上下文類型的通用定義。
- 屬性
備註
在使用 options 實例序列化與反序列化型別時,這些型別的元資料會從上下文實例擷取。
該方法支援在每個選項實例中新增多個上下文。 元資料會依設定順序解析,類似於解析元資料的方式 Combine(IJsonTypeInfoResolver[]) 。