> This page is for SDKs, version Legacy.
> For other versions, use one of these documentation indexes:
> - Current (default): https://buildwithfern.com/learn/sdks/current/llms.txt
> - Legacy: https://buildwithfern.com/learn/sdks/legacy/llms.txt

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt.

## 1.12.0-rc17

**`(fix):`** Generate snippets for unions when `use-discriminated-unions` is `true` in the generator configuration.

## 1.12.0-rc16

**`(fix):`** Remove hardcoded namespace import from JsonElementComparer.cs

## 1.12.0-rc15

**`(feat):`** Generate **discriminated unions** with:

* Type safety with compile-time checking
* Exhaustive discriminant value matching
* JSON serialization support

Here's a simple example how to use a shape discriminated union:

```csharp
var shape = new Shape(new Circle { Radius = 5 });

// Type checking
if (shape.IsCircle) {
    Console.WriteLine($"Radius: {circle.AsCircle().Radius}");
}

// Discriminant value matching
var area = shape.Match(
    circle => Math.PI * circle.Radius * circle.Radius,
    square => square.Length * square.Length,
    (type, _) => throw new NotSupportedException($"Unknown: {type}")
);

// TryAs pattern
if (shape.TryAsCircle(out var circle)) {
    Console.WriteLine($"Radius: {circle.Radius}");
}
```

This feature is off by default for backward compatibility.
To enable it, set `use-discriminated-unions` to `true` in the generator configuration.

**`(feat):`** Improved serialization tests for generated classes for normal objects and discriminated unions.

**`(feat):`** Generated classes now follow the C# convention for odering consts, fields, constructors, properties, methods, operators, and inner classes.