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:

1var shape = new Shape(new Circle { Radius = 5 });
2
3// Type checking
4if (shape.IsCircle) {
5 Console.WriteLine($"Radius: {circle.AsCircle().Radius}");
6}
7
8// Discriminant value matching
9var area = shape.Match(
10 circle => Math.PI * circle.Radius * circle.Radius,
11 square => square.Length * square.Length,
12 (type, _) => throw new NotSupportedException($"Unknown: {type}")
13);
14
15// TryAs pattern
16if (shape.TryAsCircle(out var circle)) {
17 Console.WriteLine($"Radius: {circle.Radius}");
18}

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.