CsvSerializerContext Class
The base class of the serializer contexts generated by the source generator, which provide the metadata of types without reflection.
public abstract class CsvSerializerContext : ICsvTypeInfoResolverRemarks
Declare a partial class that derives from this class, with a CsvSerializableAttribute for each type to serialize. The generator adds a Default instance and a property per type that returns its CsvTypeInfo<T>, to pass to the methods of CsvSerializer. This works with trimming and Native AOT.
Example
[CsvSerializable(typeof(Product))]
[CsvSerializable(typeof(Person))]
[CsvSourceGenerationOptions(Separator = ';')]
public partial class AppCsvContext : CsvSerializerContext
{
}- Implements
Constructors
| Name | Description |
|---|---|
| CsvSerializerContext(CsvSerializerOptions?) | Initializes a new instance of the CsvSerializerContext class. |
CsvSerializerContext(CsvSerializerOptions?)
CsvSerializerContext.csInitializes a new instance of the CsvSerializerContext class.
protected CsvSerializerContext(CsvSerializerOptions? options)Parameters
optionsCsvSerializerOptions?- The options of the context, or
nullfor the default options. The context uses a copy whoseCsvSerializerOptions.TypeInfoResolveris the context.
Properties
| Name | Description |
|---|---|
| Options | Gets the options of the context. Their CsvSerializerOptions.TypeInfoResolver is the context. |
Options
CsvSerializerContext.csGets the options of the context. Their CsvSerializerOptions.TypeInfoResolver is the context.
public CsvSerializerOptions Options { get; }Property value
Methods
| Name | Description |
|---|---|
| GetOrCreateTypeInfo<T>() | Gets the metadata of a type for CsvSerializerContext.Options, creating it on first use. |
| GetTypeInfo(Type, CsvSerializerOptions) | Gets the serialization metadata of a type. |
GetOrCreateTypeInfo<T>()
CsvSerializerContext.csGets the metadata of a type for CsvSerializerContext.Options, creating it on first use.
protected CsvTypeInfo<T> GetOrCreateTypeInfo<T>()GetTypeInfo(Type, CsvSerializerOptions)
Gets the serialization metadata of a type.
public abstract CsvTypeInfo? GetTypeInfo(Type type, CsvSerializerOptions options)Parameters
typeType- The type.
optionsCsvSerializerOptions- The options the metadata is created for.
Returns
CsvTypeInfo? The metadata, or null when the resolver does not support type.