Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

dotnet-source-gen-options-validation

/dotnet-source-gen-options-validation

Przekształca walidację opcji na generator źródeł działający w czasie kompilacji, zgodny z AOT i bez refleksji, jako zamiennik ValidateDataAnnotations.

Repozytorium
claude ↗
Licencja
MIT
Ostatnia zmiana repozytorium
15.09.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
1
Przestarzałość

Brak sygnałów. Repozytorium zmienione 15.09.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Przekształca walidację opcji na generator źródeł działający w czasie kompilacji, zgodny z AOT i bez refleksji, jako zamiennik ValidateDataAnnotations.

Wyzwalacze z opisu

OptionsValidator,options validation source gen,AOT options validation,compile-time validation,ValidateDataAnnotations replacement,reflection-free validation.
Oryginalny opis (EN)

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.

Jak działa

  1. When to Use
  2. Steps
  3. Supported Validation Attributes
  4. Notes
Sekcje z nagłówków SKILL.md, w oryginale · 70 linii, 320 słów
Podgląd SKILL.md
---
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
metadata:
  author: Im5tu
  version: "1.0"
  repositoryUrl: https://github.com/im5tu/dotnet-skills
allowed-tools: Bash(dotnet:*), Read, Edit, Write, Glob, Grep, AskUserQuestion
---

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

Wersje

W bazie nie ma innych skilli o nazwie dotnet-source-gen-options-validation.

Migawka bazy z 13.11.2026 · wersja paczki cb557c5e8364 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100dotnet-source-gen-json
    Konfiguruje generowanie źródeł System.Text.Json dla serializacji JSON zgodnej z AOT, z JsonSerializerContext i JsonSerializable, bez refleksji.
  • 100dotnet-source-gen-logging
    Przekształca logowanie na generator źródeł LoggerMessage, aby uzyskać wydajne logowanie zgodne z AOT i ustrukturyzowane logi.
  • 100mapperly
    Prowadzi przez Mapperly, mapper obiektów generowany w czasie kompilacji: mapowanie wydajne i bez refleksji, walidacja mapowań przy kompilacji, zgodność z AOT oraz mapowanie enumów i kolekcji.
  • 84using-generated-regex
    Wdraża w .NET wyrażenia regularne generowane podczas kompilacji przez GeneratedRegexAttribute, dla wydajności i AOT.
  • 100dotnet-aot-compat
    Dostosowuje projekty .NET do Native AOT i trimmingu przez systematyczne usuwanie ostrzeżeń analizatora IL (IL2026, IL2070, IL3050), dodawanie adnotacji DynamicallyAccessedMembers i włączanie IsAotCompatible.
  • 90dotnet-performance-aot-review
    Przegląda wydajność .NET oraz gotowość do Native AOT i trimmingu: pułapki refleksji i serializacji, alokacje na gorących ścieżkach, narzut async, cache, ostrzeżenia IL2xxx i dyscyplinę benchmarków.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.