csharp-idioms

Apply modern C# idioms respecting TargetFramework and LangVersion constraints.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill csharp-idioms
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-idioms
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/core/csharp-idioms
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill csharp-idioms

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Modernizes C# code by reducing boilerplate, improving consistency, and ensuring idiomatic use of records, pattern matching, primary constructors, and file-scoped namespaces without emitting syntax unsupported by the project's target framework.

Core Features & Use Cases

  • Guidance on modern syntax: Prefer file-scoped namespaces, records for DTOs/value objects, pattern matching, and expression-bodied members.
  • Feature gating: Recommend features only when supported by TargetFramework and LangVersion to avoid incompatible code generation.
  • Detection & migration: Scan .csproj, Directory.Build.props, .editorconfig, and existing .cs files to detect current patterns and suggest incremental migrations.
  • Practical patterns: Includes examples for records, primary constructors, collection expressions, switch/property/list patterns, and naming conventions.

Quick Start

Use the csharp-idioms skill to refactor new DTOs into records, apply file-scoped namespaces, and choose idioms compatible with the project's TargetFramework and LangVersion.

Frequently Asked Questions about csharp-idioms

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor DTOs to use records in C#?

To refactor DTOs to use records in C#, replace class definitions with record types to reduce boilerplate and improve consistency. The skill scans existing .cs files and suggests incremental migrations to records for DTOs and value objects.

How do I migrate C# code to file-scoped namespaces?

Migrating C# code to file-scoped namespaces involves moving the namespace declaration to a single line ending with a semicolon. The skill detects existing patterns in .cs files and applies this modern syntax to improve code consistency.

Does C# primary constructors work with older .NET TargetFramework versions?

Primary constructors for DI services require a compatible LangVersion and TargetFramework. The skill enforces compatibility by checking .csproj and Directory.Build.props, gating feature use to avoid emitting unsupported syntax during code generation.

What is the best way to apply pattern matching refactors in .NET?

The best way to apply pattern matching refactors in .NET is to adopt switch expressions, property patterns, and list patterns. The skill guides these refactors during code generation and migration while ensuring compatibility with your project's framework version.

Can I use collection expressions in C# without updating the LangVersion?

Collection expressions require a specific LangVersion and TargetFramework to compile correctly. The skill checks your .editorconfig and .csproj settings to gate feature recommendations, preventing incompatible code generation.

Why does my modern C# code generation fail on older .NET projects?

Modern C# code generation fails on older .NET projects when features like records or primary constructors are used without checking the TargetFramework and LangVersion. The skill gates feature use by framework version to prevent incompatible syntax.