The OptionsValidator source generator in .NET 8+ automatically generates IValidateOptions<T> implementations at compile time from Data Annotation attributes. Instead of using reflection-based ValidateDataAnnotations(), you declare an empty partial class with [OptionsValidator], and the generator emits a fully optimized,
Table of contents
The problem with runtime data annotationsHow it worksA minimal exampleWhat the generator actually emitsNested options validationAOT and trimming compatibilitySummaryMore informationSort: