There are special use-cases that each language supports; this document pertains to C# models.
- Generate serializer and deserializer functionality
- Generate models with equals and GetHashCode methods
- Generate models with auto-implemented properties
- Change the collection type for arrays
- Generate custom enum value names
- Generate models with inheritance
Sometimes you want to serialize the data models into JSON. In order to do that use the preset CSHARP_JSON_SERIALIZER_PRESET
External dependencies: Requires System.Text.Json, System.Text.Json.Serialization and System.Text.RegularExpressions to work.
Check out this example for a live demonstration.
To overwrite the Equal
and GetHashCode
methods, use the preset CSHARP_COMMON_PRESET
and provide the options equal: true
and hashCode: true
Check out this example for a live demonstration.
To generate auto-implemented properties (the ones with with { get; set; }
accessors), use the preset CSHARP_COMMON_PRESET
and provide the option autoImplementedProperties: true
Check out this example for a live demonstration.
If you consider the Array Class to be insuitable for your situation, then you might look into setting the collectionType: 'List'
option to your instance of the generator. This will cause all of the collections to be rendered as of type System.Collections.Generic.IEnumerable<T>
.
Check out this example for a live demonstration.
When using AsyncAPI or JSON Schema, it is not possible to associate enum names with values however with extensions it is.
Check out this example for a live demonstration.
If you want the generated models to inherit from a custom class, you can overwrite the existing rendering behavior and create your own class setup.
Check out this example for a live demonstration.