Skip to content

CSharpGeneratorSettings

Srivathsan Jayaraman edited this page Jun 1, 2020 · 16 revisions

Inherits from CodeGeneratorSettingsBase

Properties:

  • Namespace: The namespace of the generated classes.
  • ClassStyle: The CSharp class style, Poco or Inpc, i.e. Plain Old CLR Object or INotifyPropertyChanged (default: 'Poco').
  • RequiredPropertiesMustBeDefined: Specifies whether a required property must be defined in JSON - sets Required.Always when the property is required (default: true).
  • GenerateDataAnnotations: Specifies whether to generate data annotation attributes on DTO classes (default: true).
  • AnyType: The any .NET type (default: 'object').
  • DateType: The date .NET type (default: 'DateTimeOffset').
  • DateTimeType: The date time .NET type (default: 'DateTimeOffset').
  • TimeType: The time .NET type (default: 'TimeSpan').
  • TimeSpanType: The time span .NET type (default: 'TimeSpan').
  • ArrayType: The generic array .NET type (default: 'ICollection').
  • DictionaryType: The generic dictionary .NET type (default: 'IDictionary').
  • ArrayInstanceType: The generic array .NET instance type (default: empty = ArrayType).
  • DictionaryInstanceType: The generic dictionary .NET instance type (default: empty = DictionaryType).
  • ArrayBaseType: The generic array .NET type (default: 'Collection').
  • DictionaryBaseType: The generic dictionary .NET type (default: 'Dictionary').
  • TypeAccessModifier: The DTO class/enum access modifier (default: public).
  • PropertySetterAccessModifier: The access modifier of property setters (default: '')
  • JsonConverters: Specifies the custom Json.NET converter types (optional, comma separated).
  • GenerateImmutableArrayProperties: Specifies whether to remove the setter for non-nullable array properties (default: false).
  • GenerateImmutableDictionaryProperties: Specifies whether to remove the setter for non-nullable dictionary properties (default: false).
  • HandleReferences: Use preserve references handling (All) in the JSON serializer (default: 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 (default: null).
  • GenerateJsonMethods: Specifies whether to render ToJson() and FromJson() methods for DTOs (default: false).
  • EnforceFlagEnums: Specifies whether enums should be always generated as bit flags (default: false).
  • InlineNamedDictionaries: Inline named dictionaries (default: false).
  • GenerateOptionalPropertiesAsNullable: Value indicating whether optional schema properties (not required) are generated as nullable properties (default: false).

JsonSerializerSettingsTransformationMethod

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;
        }
    }
}
Clone this wiki locally