Skip to content

Latest commit

 

History

History
56 lines (31 loc) · 2.98 KB

Csharp.md

File metadata and controls

56 lines (31 loc) · 2.98 KB

C#

There are special use-cases that each language supports; this document pertains to C# models.

Generate serializer and deserializer functionality

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.

Generate models with equals and GetHashCode methods

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.

Generate models with auto-implemented properties

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.

Change the collection type for arrays

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.

Generate custom enum value names

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.

Generate models with inheritance

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.