dotnet-csharp-modern-patterns

Applies modern C# language features matched to the project's target framework version.

Updated May 22, 2026
One-click install
npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill dotnet-csharp-modern-patterns-viniciuscs84
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-csharp-modern-patterns
Source: https://github.com/viniciuscs84/sdd-toolkit/tree/main/skills/dotnet-csharp-modern-patterns
Command: npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill dotnet-csharp-modern-patterns-viniciuscs84

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Developers often misuse modern C# features that are unavailable on their target framework, causing compile errors or inconsistent code. This Skill maps each language feature to the correct TFM and C# version so code always compiles and follows current idioms. ## Core Features & Use Cases - TFM-to-Version Mapping: A quick reference table links net8.0 through net11.0 to C# 12-15 and their key features. - Feature Guidance with Guardrails: Covers records, primary constructors, collection expressions, pattern matching, required members, the field keyword, extension blocks, params collections, Lock, and partial properties, each with version constraints and gotchas. - Multi-Targeting Support: Provides polyfill strategies (PolySharp, Polyfill, conditional compilation) for using newer syntax on older targets. - Use Case: When writing a new service on net8.0, use this Skill to apply primary constructors for DI injection and collection expressions for initialization, while avoiding net10.0-only features like the field keyword. ## Quick Start Ask the assistant to review or write C# code using modern language features appropriate for the project's target framework, running dotnet-version-detection first to determine the TFM.

Frequently Asked Questions about dotnet-csharp-modern-patterns

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

FAQPage Schema
How do I use primary constructors in C# for dependency injection?

Declare constructor parameters directly on the class, such as public class OrderService(IOrderRepository repo), and use the captured parameters in methods. Note that captured parameters are mutable, so assign to a readonly field when immutability matters.

Which C# version corresponds to each .NET target framework?

net8.0 maps to C# 12, net9.0 to C# 13, net10.0 to C# 14, and net11.0 to C# 15 preview. Each version unlocks specific features like collection expressions in C# 12 or the field keyword in C# 14.

When should I use records vs classes in C#?

Use records for DTOs and API responses where value equality matters, and readonly record structs for small domain value objects. Use classes for entities with identity such as User or Order, or when you need traditional inheritance semantics.

Can I use the C# field keyword on .NET 8?

No, the field keyword requires C# 14 and net10.0 or later. On earlier TFMs, declare a traditional private backing field with a property that applies your validation logic in the setter.

How do I use newer C# features when multi-targeting older frameworks?

Use PolySharp to polyfill compiler-required types like IsExternalInit so records and required members compile on older targets, and Polyfill for runtime APIs. For features that cannot be polyfilled, use #if conditional compilation per TFM.