Class CodeGenOptions
Options for CSharpCodeGenerator.
public sealed class CodeGenOptions
- Inheritance
-
CodeGenOptions
- Inherited Members
Properties
- Accessibility
Gets the accessibility of generated types. Defaults to Public.
- ApacheCompatible
Gets whether generated types also work with Apache.Avro's specific API (
SpecificDatumWriter/Reader): records implementAvro.Specific.ISpecificRecord, fixed types derive fromAvro.Specific.SpecificFixed, and logical types use Apache's .NET types (DateTimefor dates and timestamps,TimeSpanfor times,Guidfor string UUIDs,Avro.AvroDecimalfor decimals), whatever LogicalTypes says. The generated code then needs a reference to Apache.Avro. Defaults to false.
- CollectionType
Gets the C# type of Avro arrays in generated records, nested arrays included. Defaults to List, which the Apache.Avro compatibility mode requires.
- Default
Gets the default options.
- LanguageVersion
Gets the major C# version the generated code may use. With 11 or later it adds, for .NET 8 and later,
IAvroSerializable<T>. It must be 7 or later. Defaults to 14.
- LogicalTypes
Gets how values of logical types are represented. Defaults to Native.
- Namespace
Gets the C# namespace for named types that have no Avro namespace. Defaults to null: such types are generated in the global namespace.
- NamespaceMap
Gets C# namespaces for Avro namespaces, as Apache.Avro's avrogen maps them with
--namespace avro:csharp. A type's namespace is replaced by the longest key that equals it or is a prefix of it at a.: withcom.examplemapped toExample,com.example.eventsbecomesExample.events. Only the C# namespace changes; the schema, and so the data and fingerprints, do not. Not supported with ApacheCompatible, since Apache.Avro finds generated types by the schema's full name. Defaults to null: no mapping.
- NullableAnnotations
Gets whether to emit nullable reference type annotations (
string?,#nullable enable), which need C# 8 or later. Without them the generated code compiles as C# 7.3, the default for netstandard2.0 and .NET Framework projects. Defaults to true; with a LanguageVersion below 8 it must be false, or generation throws ArgumentException.
- PropertyNames
Gets how record fields become property names, or null (the default) for the mode's own: PascalCase, or with ApacheCompatible Avro, the names Apache.Avro's avrogen uses.
- RequiredMembers
Gets whether record fields without a schema default are
requiredmembers (#15), so the compiler checks thatnewsets them. They are only on targets that support them, .NET 7 and later, and with C# 11 or later (LanguageVersion); elsewhere they stay plain properties, so the code compiles for every target. Readers create values through a constructor that sets the members. Defaults to false.
- SealedTypes
Gets whether generated records and fixed types are
sealed. Defaults to true; with false, the user may derive from them. Readers always create the generated type itself, and the writers write only its fields.
- TargetHasDateOnly
Gets whether the target framework has
System.DateOnlyandSystem.TimeOnly(.NET 6 and later). When it does not,datemaps toDateTimeandtime-*toTimeSpan. Defaults to true.