JsonSerializerOptions.TryGetTypeInfo(Type, JsonTypeInfo) Method

Definition

Tries to get the JsonTypeInfo contract metadata resolved by the current JsonSerializerOptions instance.

C#
public bool TryGetTypeInfo(Type type, out System.Text.Json.Serialization.Metadata.JsonTypeInfo? typeInfo);

Parameters

type
Type

The type to resolve contract metadata for.

typeInfo
JsonTypeInfo

When this method returns, contains the resolved contract metadata, or null if the contract could not be resolved.

Returns

true if a contract for type was found, or false otherwise.

Exceptions

type is null.

type is not valid for serialization.

Remarks

Returned metadata can be downcast to JsonTypeInfo<T> and used with the relevant JsonSerializer overloads.

If the JsonSerializerOptions instance is locked for modification, the method will return a cached instance for the metadata.

Applies to

Produkt Versioner
.NET 8 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided)