JsonSerializerOptions.AddContext<TContext> Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Varning
JsonSerializerOptions.AddContext is obsolete. To register a JsonSerializerContext, use either the TypeInfoResolver or TypeInfoResolverChain properties.
Lägger till en ny JsonSerializerContext i metadataupplösningen för den aktuella JsonSerializerOptions instansen.
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}) ()
Typparametrar
- TContext
Den allmänna definitionen av den angivna kontexttypen.
- Attribut
Kommentarer
När du serialiserar och deserialiserar typer med hjälp av alternativinstansen hämtas metadata för typerna från kontextinstansen.
Metoderna har stöd för att lägga till flera kontexter per alternativinstans. Metadata löses i konfigurationsordningen, ungefär som hur Combine(IJsonTypeInfoResolver[]) metadata matchas.