AutoSDK
Reference

Model Styles

Choose between Class, Record, and ReadonlyRecordStruct for generated model types.

AutoSDK supports three C# code styles for generated model types, controlled by --modelStyle (CLI) or AutoSDK_ModelStyle (MSBuild).

Class (Default)

Generates standard C# classes with get/set properties:

public sealed partial class Pet
{
    [JsonPropertyName("name")]
    public string Name { get; set; } = default!;

    [JsonPropertyName("status")]
    public PetStatus? Status { get; set; }

    [JsonPropertyName("tags")]
    public IList<Tag>? Tags { get; set; }
}

Best for: Most use cases. Familiar, mutable, works everywhere.

Record

Generates C# record types with init-only properties:

public sealed partial record Pet
{
    [JsonPropertyName("name")]
    public string Name { get; init; } = default!;

    [JsonPropertyName("status")]
    public PetStatus? Status { get; init; }

    [JsonPropertyName("tags")]
    public IList<Tag>? Tags { get; init; }
}

Best for: Immutable-by-default APIs, value equality semantics, with expressions.

Requires: C# 9+ (net5.0 or later)

ReadonlyRecordStruct

Generates readonly record struct types (value types):

public readonly partial record struct Pet
{
    [JsonPropertyName("name")]
    public string Name { get; init; }

    [JsonPropertyName("status")]
    public PetStatus? Status { get; init; }

    [JsonPropertyName("tags")]
    public IList<Tag>? Tags { get; init; }
}

Best for: High-performance scenarios where you want to avoid heap allocations. Small models only — large structs have copy overhead.

Requires: C# 10+ (net6.0 or later)

Comparison

FeatureClassRecordReadonlyRecordStruct
AllocationHeapHeapStack
MutabilityMutableImmutable (init)Immutable (init)
EqualityReferenceValueValue
with expressionNoYesYes
InheritanceYesYesNo
Min frameworkAnynet5.0+net6.0+

Configuration

CLI:

autosdk generate spec.json --modelStyle Record

MSBuild:

<AutoSDK_ModelStyle>Record</AutoSDK_ModelStyle>
Edit on GitHub

Last updated on

On this page