TOML to C# Class Generator
Automatically generate C# classes from your TOML configuration files. This tool creates ready-to-use POCO classes with JSON serialization attributes, perfect for .NET applications using config files. Supports both Newtonsoft.Json and System.Text.Json.
How the TOML to C# Class Generator Works
This tool converts TOML configuration files into C# classes with JSON/TOML serialization attributes. Paste your TOML content and get ready-to-use C# POCO classes for deserializing configuration in .NET applications.
The converter maps TOML types to C# types: strings to string, integers to int or long, floats to double, booleans to bool. Nested tables become nested classes. Arrays become List<T> or arrays.
Generated classes include serialization attributes for Newtonsoft.Json, System.Text.Json, or TOML-specific libraries. Copy the code into your .NET project and deserialize TOML configs with a single method call.
When You'd Actually Use This
Building .NET applications with TOML config
Your .NET app uses TOML for configuration. Generate strongly-typed classes, deserialize with Tomlyn or NETToml, access settings with IntelliSense support.
Creating Unity game configurations
Unity games often use config files for game balance. Generate C# classes from TOML, load settings at runtime, tweak game parameters without recompiling.
Migrating from appsettings.json
Switching from JSON to TOML config in ASP.NET Core? Regenerate your configuration classes with TOML attributes. The class structure remains similar.
Documenting configuration options
Generated classes document available configuration options. Team members can browse properties in Visual Studio instead of reading separate documentation.
Validating configuration at compile time
Strong typing catches configuration errors at compile time. Misspelled property names become compiler errors, not runtime surprises.
Building configuration editors
Use generated classes to power config editors. Reflect over properties to build UI, validate input against property types, serialize back to TOML.
What to Know Before Using
Choose the right serialization library.Tomlyn is popular for TOML in .NET. NETToml is another option. Some use Newtonsoft.Json with TOML converted to JSON first. Pick based on your project needs.
Nullable types for optional fields.Use nullable types (string?, int?) for optional configuration values. Null indicates the field wasn't specified in the TOML file.
Property naming conventions.C# uses PascalCase for properties. TOML typically uses snake_case. Serialization attributes map between the two naming conventions automatically.
Default values require initialization.Set default values in property initializers or constructors. TOML deserialization preserves defaults for missing fields.
Pro tip: Add XML documentation comments to your TOML before generating. Some tools preserve these as C# XML docs, making your classes self-documenting.
Common Questions
Which .NET TOML library is best?
Tomlyn is modern and well-maintained. NETToml is simpler. For ASP.NET Core, consider built-in configuration providers with TOML support.
How do I handle nested TOML tables?
Nested tables become nested C# classes. Each table level generates a new class. Properties reference nested classes for the full hierarchy.
Can I add validation attributes?
Yes, add DataAnnotations like [Required], [Range], [StringLength] to generated properties. Validate configuration with Validator.TryValidateObject().
What about TOML arrays?
TOML arrays become List<T> or T[] in C#. The element type T is inferred from array contents. Homogeneous arrays work best.
How do I deserialize TOML to my class?
With Tomlyn: var config = Toml.ToModel<MyConfig>(tomlString). With other libraries, use their deserialization API with your generated class type.
Can I use records instead of classes?
For .NET 5+, you can modify generated code to use records. Records provide immutability and value equality. Great for configuration objects.
How do I handle missing fields?
Use nullable types or default values. Deserialization won't fail for missing fields unless your library is configured for strict mode.
Other Free Tools
TOML to JSON Converter
Convert TOML to JSON Instantly
JSON to TOML Converter
Convert JSON to TOML Online
TOML Validator and Linter
Validate and Lint Your TOML Files
TOML Beautifier and Formatter
Beautify and Format TOML Code
TOML to YAML Converter
Convert TOML to YAML Easily
ASCII to Hex Converter
ASCII to Hex Converter: Text to Hexadecimal Translator
Barcode Generator
Free Barcode Generator
Binary to Text Converter
Binary to Text Converter
Free Printable Calendar Maker
Create & Print Your Custom Calendar
Pie Chart Maker
Free Pie Chart Maker Online