-
-
Notifications
You must be signed in to change notification settings - Fork 535
CSharpGeneratorSettings
Jim edited this page Mar 25, 2024
·
16 revisions
- Package: NJsonSchema.CodeGeneration
- Settings for: CSharpGenerator
- Class: CSharpGeneratorSettings.cs
Inherits from CodeGeneratorSettingsBase
Property | Description | Default Value |
---|---|---|
Namespace | Namespace of the generated classes | 'MyNamespace' |
ClassStyle | The CSharp class style, Poco or Inpc ,i.e. Plain Old CLR Object or INotifyPropertyChanged |
'Poco' |
TypeAccessModifier | The access modifier for DTO classes and enums | 'public' |
PropertySetterAccessModifier | The access modifier for property setters | '' |
JsonConverters | Custom Json.NET converter types (optional, comma separated) |
Property | Description | Default Value |
---|---|---|
AnyType | The .NET type for 'any' | 'object' |
DateType | The .NET type for 'date' | 'DateTimeOffset' |
DateTimeType | The .NET type for 'datetime' | 'DateTimeOffset' |
TimeType | The .NET type for 'time' | 'TimeSpan' |
TimeSpanType | The .NET type for 'time span' | 'TimeSpan' |
NumberType | The .NET type for 'number' | 'double' |
NumberFloatType | The .NET type for 'number' with the format 'float' | 'float' |
NumberDoubleType | The .NET type for 'number' with the format 'double' | 'double' |
NumberDecimalType | The .NET type for 'number' with the format 'decimal' | 'decimal' |
InlineNamedTuples | Specifies whether named/referenced tuples should be inlined or generated as class with tuple inheritance |
true |
Property | Description | Default Value |
---|---|---|
ArrayType | The generic array .NET type | 'ICollection' |
ArrayBaseType | The generic array .NET type | 'Collection' |
ArrayInstanceType | The generic array .NET instance type | (empty = ArrayType) |
GenerateImmutableArrayProperties | Specifies whether to remove the setter for non-nullable array properties | false |
InlineNamedArrays | Specifies whether named/referenced arrays should be inlined or generated as class with array inheritance | false |
Property | Description | Default Value |
---|---|---|
DictionaryType | The generic dictionary .NET type | 'IDictionary' |
DictionaryBaseType | The generic dictionary .NET type | 'Dictionary' |
DictionaryInstanceType | The generic dictionary .NET instance type | (empty = DictionaryType) |
GenerateImmutableDictionaryProperties | Specifies whether to remove the setter for non-nullable dictionary properties | false |
InlineNamedDictionaries | Inline named dictionaries | false |
Property | Description | Default Value |
---|---|---|
JsonLibrary | The C# JSON library to use ('NewtonsoftJson' or 'SystemTextJson'). 'SystemTextJson' is experimental/not complete | 'NewtonsoftJson' |
HandleReferences | Use preserve references handling (All) in the JSON serializer | false |
JsonSerializerSettingsTransformationMethod | The name of a static method which is called to transform the JsonSerializerSettings used in the generated ToJson() /FromJson() methods, more info see below |
null |
GenerateJsonMethods | Specifies whether to render ToJson() and FromJson() methods for DTOs | false |
EnforceFlagEnums | Specifies whether enums should be always generated as bit flags | false |
GenerateOptionalPropertiesAsNullable | Specifies whether optional schema properties (not required) are generated as nullable properties | false |
GenerateNullableReferenceTypes | Specifies whether to generate Nullable Reference Type annotations | false |
RequiredPropertiesMustBeDefined | Specifies if required properties must be defined in JSON - sets Required.Always when the property is required |
true |
GenerateDataAnnotations | Specifies whether to generate data annotation attributes on DTO classes | true |
For example, you can implement the following class and set the method to MyNamespace.SerializerSettings.TransformSettings
:
namespace MyNamespace
{
internal static class SerializerSettings
{
public static JsonSerializerSettings TransformSettings(
JsonSerializerSettings settings)
{
settings.DateParseHandling = DateParseHandling.DateTimeOffset;
return settings;
}
}
}