Skip to content
Agentmart
Submit a tool

dotnet-source-gen-options-validation

Converts options validation to use the compile-time source generator for AOT-compatible, reflection-free validation.

Skill by Im5tu

IndexedMIT★ 6
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/im5tu-dotnet-source-gen-options-validation

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Converts options validation to use the compile-time source generator for AOT-compatible, reflection-free validation. Also use when the user mentions "OptionsValidator," "options validation source gen," "AOT options validation," "compile-time validation," "ValidateDataAnnotations replacement," or "reflection-free validation." For full AOT analysis, see dotnet-aot-analysis.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/dotnet-source-gen-options-validation

Tools it pre-approves 7

From allowed-tools in SKILL.md: the agent may use these without asking you each time.

  • Bash(dotnet:*),
  • Read,
  • Edit,
  • Write,
  • Glob,
  • Grep,
  • AskUserQuestion

What's inside

Skill name
dotnet-source-gen-options-validation
Description
Converts options validation to use the compile-time source generator for AOT-compatible, reflection-free validation. Also use when the user mentions "OptionsValidator," "options validation source gen," "AOT options validation," "compile-time validation," "ValidateDataAnnotations replacement," or "reflection-free validation." For full AOT analysis, see dotnet-aot-analysis.
License
MIT
Allowed tools
Bash(dotnet:*),, Read,, Edit,, Write,, Glob,, Grep,, AskUserQuestion
Metadata
author: Im5tu · version: 1.0 · repositoryUrl: https://github.com/im5tu/dotnet-skills
Instructions
70 lines in SKILL.md · view on GitHub

Before installing

  • Pre-approves some shell commands

Files (1)

  • SKILL.md

SKILL.md (first lines)

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

1. **Find options classes** with data annotations:
   - Search for classes using `[Required]`, `[Range]`, `[RegularExpression]`, `[MaxLength]`, `[MinLength]`, `[Length]`
   - These are typically in files matching `*Options.cs` or `*Settings.cs`

2. **Check existing validation setup**:
   - If class already has a corresponding `[OptionsValidator]` partial class, skip it
   - Note any existing `ValidateDataAnnotations()` calls for removal later

3. **For each options class**, create a partial validator class:
   ```csharp
   [OptionsValidator]
   public partial class Validate{OptionsClassName} : IValidateOptions<{OptionsClassName}>
   {
   }
   ```
   - Place the validator in the same namespace as the options class
   - The source generator will implement the validation logic at compile time

4. **Register the validator in DI**:
   ```csharp
   services.AddSingleton<IValidateOptions<MyOptions>, ValidateMyOptions>();
   ```
   - Replace any existing `ValidateDataAnnotations()` calls
   - Ensure `Microsoft.Extensions.Options` using directive is present

5. **Verify with build**:
   ```bash
   dotnet build
   ```

6. **If build fails**, check for:
   - Missing `partial` keyword on validator class
   - Unsupported validation attributes
   - Missing package reference to `Microsoft.Extensions.Options`

7. **Report results**:
   - List all validator classes created
   - List all DI registrations added
   - Confirm build status

## Supported Validation Attributes

- `[Required]` - Property must have a value
- `[Range]` - Numeric value within specified range
- `[RegularExpression]` - String matches regex pattern
- `[MaxLength]` - Maximum length for strings/collections
- `[MinLength]` - Minimum length for strings/collections
- `[Length]` - Exact or range length constraint

## Notes

- Requires .NET 8.0 or higher
- Requires `Microsoft.Extensions.Options` version 8.0 or higher
- `ValidateDataAnnotations()` is NOT needed and should be removed
- The `[OptionsValidator]` attribute triggers source generation
- Validation runs at startup when options are first resolved
- Unsupported attributes will produce compiler warnings

From Im5tu/claude, MIT.

More from Im5tu/claude

Signals

Stars
6
Forks
3
Open issues
0
Last commit (this folder)
Aug 21, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

Version
1.0
License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Im5tu

Cite this page

dotnet-source-gen-options-validation skill. Agent Mart. https://agentmart.dev/skills/im5tu-dotnet-source-gen-options-validation (last updated 2026-10-24)