About the YAML to C# Converter
Binding a YAML configuration file in a .NET service means writing a class that mirrors it, and hand-writing that class is tedious and easy to get subtly wrong. This generator parses your YAML, walks the resulting object graph and emits one class per distinct mapping shape. Keys become PascalCase auto-properties, nested mappings become their own classes named after the key, and a sequence of mappings becomes List<T> of the generated type.
Types come from the parsed values, not from guesswork on the raw text: whole numbers become int, decimals become double, true and false become bool, dates resolved by the YAML loader become DateTime, and anything empty becomes object. Because the original key rarely matches the C# property name once it is PascalCased, each property carries a name attribute; choose System.Text.Json or Newtonsoft.Json style, or switch attributes off entirely if you bind with a naming convention.
Two mappings with identical key sets are merged into a single class, so a list of similar records does not produce a class per element. Where a list holds mappings with differing keys, the keys are merged so no field is lost. Fill in the namespace box to wrap everything in a namespace block. For the same job starting from JSON, use JSON to C#.
How to use
- Paste your YAML configuration or upload the file.
- Set the root class name, and a namespace if you want the output wrapped.
- Pick the attribute style that matches your serializer, or turn attributes off.
- Copy the classes or download
Model.csinto your project.
Common questions
- Why is a number typed as double rather than decimal?
- The YAML loader returns a floating point value and double is its closest C# match. Change it to decimal by hand for money fields.
- What happens to keys with dashes or dots?
- They are PascalCased for the property name, and the original key is preserved in the serializer attribute so binding still works.
- Can it generate records instead of classes?
- Not yet. The output is classes with get and set accessors, which is what most configuration binders expect.
- How are empty values typed?
- A null or empty value has no type information, so the property is generated as
objectfor you to narrow.