Επεξεργασία

Κοινή χρήση μέσω


JsonSerializerOptions.AddContext<TContext> Method

Definition

Caution

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

Appends a new JsonSerializerContext to the metadata resolution of the current JsonSerializerOptions instance.

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}) ()

Type Parameters

TContext

The generic definition of the specified context type.

Attributes

Remarks

When serializing and deserializing types using the options instance, metadata for the types will be fetched from the context instance.

The methods supports adding multiple contexts per options instance. Metadata will be resolved in the order of configuration, similar to how Combine(IJsonTypeInfoResolver[]) resolves metadata.

Applies to