C# Code Generation
paradox generate --csharp [--path PATH]
Product Types
Input:
type Person
name: Text
age: Integer
admin: Boolean
Output:
public sealed record Person(
string Name,
long Age,
bool Admin
);
Products become C# 10 records with positional parameters.
Validators
public static string? ValidatePerson(Person x)
{
var errors = new List<string>();
return errors.Count > 0 ? string.Join("; ", errors) : null;
}
Validators return string? where null means valid and a non-null string contains the error message.
Type Mapping
| Paradox | C# |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Union Types
Simple unions (all nullary) become C# enums:
public enum Cheese
{
Farmers,
Cheddar
}
Complex unions (with payloads) become abstract record hierarchies:
public abstract record Result
{
public sealed record Ok(string Value) : Result;
public sealed record Error(string Msg) : Result;
}
Wrap Types
public readonly record struct Email(string Value)
{
public static Email Wrap(string value) => new(value);
public string Unwrap() => Value;
}