dotnet-source-gen-options-validation
Installation
SKILL.md
Convert options validation to use the compile-time source generator, enabling AOT-compatible, reflection-free validation at startup.
When to Use
- Preparing application for Native AOT compilation
- Eliminating reflection-based validation overhead
- Ensuring validation errors surface at compile time rather than runtime
- Migrating from
ValidateDataAnnotations()to source-generated validation
Steps
-
Find options classes with data annotations:
- Search for classes using
[Required],[Range],[RegularExpression],[MaxLength],[MinLength],[Length] - These are typically in files matching
*Options.csor*Settings.cs
- Search for classes using
-
Check existing validation setup:
- If class already has a corresponding
[OptionsValidator]partial class, skip it - Note any existing
ValidateDataAnnotations()calls for removal later
- If class already has a corresponding