modern-csharp

Refactor .NET 8+ code to modern C# with LangVersion and TargetFramework gating.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Many .NET projects either miss out on newer C# capabilities or accidentally emit syntax the project cannot compile; this Skill helps teams adopt modern C# language features while ensuring compatibility with project targets and language versions.

Core Features & Use Cases

  • Language gating: Detect and respect LangVersion and TargetFramework to avoid emitting unsupported syntax.
  • Pattern detection: Scan for existing records, primary constructors, collection initializers, and required members to inform safe refactors.
  • Refactor guidance: Recommend or apply conversions such as DTOs to sealed records, services to primary-constructor classes, and collection expressions where supported.
  • Use cases: Migrating a project to .NET 8 to leverage primary constructors, updating libraries to use collection expressions, or enforcing modern, concise patterns in new greenfield projects.

Quick Start

Use the modern-csharp skill to scan the repository, verify LangVersion and TargetFramework, and recommend or apply safe refactors like converting DTOs to sealed records and replacing collection initializers when the project supports C# 12 or higher.

Frequently Asked Questions about modern-csharp

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

FAQPage Schema
How do I safely refactor DTOs to sealed records in a .NET 8 project?

Apply modern C# language features safely by scanning for existing records and primary constructors, then converting DTOs to sealed records after verifying the project targets .NET 8 or higher.

Can I use collection expressions if my multi-target library supports older .NET frameworks?

Collection expressions are gated by LangVersion and TargetFramework checks; the Skill detects project targets to avoid emitting unsupported syntax for older frameworks, ensuring compatibility across multi-target libraries.

What is the best way to adopt primary constructors without breaking existing services?

The best way to adopt primary constructors is to scan for existing patterns and recommend safe refactors for services, ensuring emitted code is gated by LangVersion checks to prevent compilation errors.

Does this code modernization approach work with projects targeting .NET 7 or earlier?

Projects targeting .NET 7 or earlier cannot use features like primary constructors and collection expressions; the Skill respects LangVersion and TargetFramework to avoid emitting syntax these older versions cannot compile.

Why does my refactored code fail to compile after converting collection initializers to collection expressions?

Compilation fails when the project LangVersion or TargetFramework does not support C# 12; the Skill detects project targets to prevent emitting unsupported syntax like collection expressions in incompatible environments.