1---2name: neo-csharp3description: Use this skill when writing, reviewing, debugging, or modernizing C# code in .NET projects. Trigger for .cs/.csproj files, C# language-version questions, nullable reference types, records, pattern matching, async/cancellation, or version-appropriate syntax from C# 10+.4---56# Modern C# (10+) Expert Skill78## Trigger On9- The user asks to write, debug, refactor, or review C# code.10- The project directory contains `*.cs`, `*.csproj`, or single-file C# scripts.11- The target framework is .NET 6.0 (LTS) and above.12- Code modernization is needed (e.g., converting legacy nested namespaces to File-scoped namespaces).1314## Workflow151. **Perceive (Version Awareness):**16 - Check `.csproj` to identify `TargetFramework` and determine the syntax upper limit:17 - `net6.0`: C# 10 (File-scoped namespaces, Global usings).18 - `net7.0`: C# 11 (Raw string literals, Required members).19 - `net8.0`: C# 12 (Primary Constructors, Collection Expressions).20 - `net9.0`: C# 13 (`params` collections, `Lock` object).21 - `net10.0`: C# 14 (Extension members, `field` keyword).222. **Reason (Planning Phase):**23 - Evaluate the modernization level of the current code to determine the refactoring strategy.24 - In lower version environments (like .NET 6), avoid using higher version syntax (like Primary Constructors), but prioritize using File-scoped namespaces.25 - In higher version environments, actively adopt new features to reduce boilerplate code.263. **Act (Execution Phase):**27 - Write high-quality code, prioritizing "syntactic sugar" to improve readability.28 - Implement strong typing and immutable data structures (`record`, `record struct`).29 - Utilize **Interpolated string handlers** and **Span<T>** to optimize performance-sensitive paths.304. **Validate (Standard Validation):**31 - Validate the safety of NRT (Nullable Reference Types).32 - Check if asynchronous operations correctly handle cancellation tokens (`CancellationToken`).33 - Ensure naming conventions comply with official .NET recommendations.3435## Feature Roadmap (C# 10 - 14)3637### C# 10 & 11 (Foundation)38- **File-scoped Namespaces:** Reduce indentation levels.39- **Global Using Directives:** Centralize common namespaces management.40- **Raw String Literals:** `"""..."""` easily handle multi-line and special characters.41- **Required Members:** Ensure required properties during object initialization.42- **List Patterns:** `if (list is [1, 2, ..])` powerful collection matching.4344### C# 12 & 13 (Productivity)45- **Primary Constructors:** Simplify class-level dependency injection.46- **Collection Expressions:** Uniformly use `[1, 2, 3]` to initialize collections.47- **`params` Collections:** Method parameters support various collection types.48- **Implicit Span Conversion:** Handle memory-safe code more naturally.4950### C# 14+ (Version-Specific Features)51- **Extension Members:** Extension properties, operators, and static members.52- **`field` Keyword:** Directly access backing fields in property logic.53- **Null-conditional Assignment:** `target?.Property = value;`.54- **Scripting:** Support `dotnet run file.cs` for direct execution.5556## Coding Standards57- **Clean Structure:** Prioritize using File-scoped namespaces.58- **Immutability:** Use `record` for Data Transfer Objects (DTO).59- **Performance:** Use `Span<T>` and `ReadOnlySpan<char>` in critical paths.60- **Async Safety:** Always pass `CancellationToken`, avoid `.Result` or `.Wait()`.6162## Deliver63- **Version-Optimized Code:** Provide the most appropriate modernized syntax code based on the target C# version.64- **Modernization Insights:** Provide specific refactoring suggestions for upgrading from older C# syntax to new features (e.g., from nested namespaces to File-scoped namespaces).65- **Syntax Explanations:** Clearly explain the design intent and syntax advantages behind the new C# features used.6667## Validate68- Ensure the provided code complies with the syntax specifications of the target C# version.69- Validate whether the code follows C# strong typing and Null safety (NRT) principles.70- Confirm the code has good readability and best practices at the pure C# language level (e.g., proper use of `Span<T>`, `record`, etc.).7172## Documentation73### Official References74- [What's new in C# 14 (Extension Members, field keyword)](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14)75- [What's new in C# 13 (params collections, Lock object)](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13)76- [What's new in C# 12 (Primary Constructors, Collection Expressions)](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-12)77- [What's new in C# 11 (Raw String Literals, Required Members)](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-11)78- [What's new in C# 10 (File-scoped Namespaces, Global Usings)](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-10)79- [Nullable Reference Types](https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references)8081### Internal References82- [C# Coding Style and Naming Conventions Guide](reference/coding-style.md)83- [C# Anti-Patterns and Best Practices](reference/anti-patterns.md)84- [Modern C# Patterns Guide](reference/patterns.md)