modern-csharp

Write version-aware modern C# code compatible with the repository's target framework and LangVersion.

Updated May 2, 2026
One-click install
npx skills add https://github.com/hdeshev/pi-config --skill modern-csharp-hdeshev
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: modern-csharp
Source: https://github.com/hdeshev/pi-config/tree/main/agent/skills/modern-csharp
Command: npx skills add https://github.com/hdeshev/pi-config --skill modern-csharp-hdeshev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? It prevents C# code from using language features that the repository's target framework or LangVersion does not support, while guiding deliberate modernization toward idiomatic C# 12, 13, and 14 patterns. ## Core Features & Use Cases - Language Ceiling Detection: Inspects TargetFramework, LangVersion, and installed SDKs to determine which C# features are actually safe to use. - Modernization Guidance: Applies primary constructors, collection expressions, records, pattern matching, raw string literals, and C# 13/14 features only where the repo supports them. - Migration References: Provides before-and-after migration patterns from C# 8 through C# 14 with validation steps like dotnet build and dotnet test. - Use Case: When upgrading a .NET 9 service, use this Skill to safely adopt C# 13 features like params collections and System.Threading.Lock without breaking the build. ## Quick Start Ask the agent to review this C# repository and modernize the code using only features supported by its target framework and LangVersion.

Frequently Asked Questions about modern-csharp

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

FAQPage Schema
How do I know which C# features my .NET project supports?▼

Check the TargetFramework and LangVersion in your csproj or Directory.Build files. .NET 9 maps to C# 13 and .NET 10 maps to C# 14; newer language versions than the target framework supports are not supported.

How to migrate older C# code to modern syntax?▼

Migrate incrementally: start with non-breaking syntax updates like switch expressions and using declarations, then adopt records and primary constructors, then collection expressions. Verify each phase with dotnet build and dotnet test.

Can I use C# 14 features on .NET 9?▼

No. C# 14 is the stable language for .NET 10, while .NET 9 supports C# 13. Using a newer language version than the target framework supports is not supported and should not be forced via LangVersion.

Should I set LangVersion to latest or preview?▼

Avoid LangVersion=latest because it makes builds machine-dependent. Use preview only when the repository intentionally opts into preview features; otherwise rely on the default version implied by the target framework.

When should I avoid primary constructors in C#?▼

Keep traditional constructors when you need multiple overloads with complex logic, significant parameter validation, explicit field visibility, or constructor chaining in base classes. Primary constructors suit simple dependency capture scenarios.