.claude/skills/gen-options-class/SKILL.md
Use when adding strongly-typed configuration to a .NET service or library. Generates an options interface, concrete class with sensible defaults, EnsureValid() startup validation, and the matching appsettings.json section. Also invoke when the user mentions: options class, IOptions, configuration class, appsettings section, settings class. Domain: Code Generation, Configuration. Level: Beginner.
npx skillsauth add klod68/littlerae gen-options-classInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Generate a validated options class for the feature: ${1:FeatureName}.
${2:MyApp}${3:e.g. ConnectionString string, ApiKey string}${4:e.g. MaxRetryCount int 3 range 0-10, TimeoutSeconds int 30 range 1-300, EnableFeatureX bool true}${5:e.g. MaxDelay must be >= InitialDelay, or none}${2}.${1}.Configuration.I${1}Options.cs
public interface with get; set; properties${2}.${1}.Configuration.${1}Options.cs
public sealed class ${1}Options : I${1}Options
{
// ── Required (no default) ──────────────────────────
public string ConnectionString { get; set; } = string.Empty;
// ── Optional (sensible defaults) ──────────────────
public int MaxRetryCount { get; set; } = 3;
// ── Validation ────────────────────────────────────
/// <summary>
/// Validates that all required settings are present and all values are within
/// valid ranges. Called eagerly by the composition root at startup.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when any setting is invalid.</exception>
public void EnsureValid()
{
// Required: throw with actionable fix message
if (string.IsNullOrWhiteSpace(ConnectionString))
throw new InvalidOperationException(
$"${1}Options.ConnectionString is required. " +
$"Configure it with: Add${1}(o => o.ConnectionString = \"...\").");
// Ranges: include actual value and valid range in message
if (MaxRetryCount is < 0 or > 10)
throw new InvalidOperationException(
$"${1}Options.MaxRetryCount must be 0–10, but was {MaxRetryCount}.");
// Cross-property (fill from context if provided)
}
}
appsettings.json sectionShow the JSON block consumers add to their configuration, with every key, its default value (or empty string for required), and a comment explaining it.
Document in a table:
| Property | Required | Default | Valid range / constraint | Error message pattern | |---|---|---|---|---|
Every InvalidOperationException message must:
${1}Options.PropertyName)EnsureValid() is the single validation entry point — no scattered if checkspublic sealed (crosses module boundary)string.Empty — never nulltools
Use when cross-cutting concerns (logging, metrics, validation, authorization) are tangled into command handlers or service methods, when building database command pipelines with reorderable concerns, or when HTTP client pipelines or message handlers need composable, independently-replaceable processing stages. Covers ICommandInterceptor interface, InterceptorPipeline with reverse-chain construction, zero-cost Empty sentinel to skip overhead when no interceptors are registered, and ConfigureAwait(false) discipline for library code. Domain: Architecture, Cross-Cutting Concerns. Level: Intermediate. Tags: interceptor, pipeline, middleware, decorator, cross-cutting-concerns.
development
Use when writing integration tests for Razor Pages, MVC, or Minimal API applications to validate routing, middleware, page rendering, and HTTP behavior without a browser or live server, or when adding fast smoke tests to a CI pipeline. Covers WebApplicationFactory<Program> setup with public partial class Program, in-memory test server, AngleSharp HTML parsing, CSS selector assertions, redirect and status code testing, and a shared static fixture pattern for minimal per-test startup overhead. Domain: Testing, ASP.NET Core. Level: Intermediate. Tags: integration-testing, webapplicationfactory, razor-pages, anglesharp, http-testing.
development
Use when designing indexes for new tables, diagnosing slow queries that are not using indexes efficiently, reviewing index fragmentation and maintenance, or when the current indexing strategy results in key lookups, table scans, or missing index warnings. Covers clustered index key selection (narrow, unique, ever-increasing), non-clustered index design for query patterns, covering indexes with INCLUDE columns, filtered indexes for subset queries, composite index column ordering, DMV-based monitoring for missing and unused indexes, and rebuild vs reorganize maintenance thresholds. Domain: Database, Performance. Level: Intermediate. Tags: index, sql-server, covering-index, filtered-index, performance, dmv, maintenance.
development
Use when building a searchable in-memory catalog or registry for documentation sites, admin panels, or type/API browsers where you need keyword matching, fuzzy search, and ranked results without an external search engine or database. Covers RegistryService with weighted scoring across name, description, keywords, and method names; Levenshtein fuzzy matching; synonym expansion; category and subcategory filtering; and singleton DI registration for datasets of hundreds to low thousands of items. Domain: Search, Data Access Patterns. Level: Intermediate. Tags: search, registry, fuzzy-matching, in-memory, catalog, filtering.