modern-csharp

Modernize C# implementations with C# 14 and .NET 10 language features.

224|87|Updated Dec 15, 2018
One-click install
npx skills add https://github.com/Resgrid/Core --skill modern-csharp-resgrid
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: modern-csharp
Source: https://github.com/Resgrid/Core/tree/main/.opencode/skills/modern-csharp
Command: npx skills add https://github.com/Resgrid/Core --skill modern-csharp-resgrid

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you reduce technical debt and runtime risk by applying modern C# language features consistently, making code more readable, efficient, and maintainable.

Core Features & Use Cases

  • Primary constructors and modern DI-friendly class design: Use public ClassName(dep1, dep2) to simplify service classes and reduce boilerplate in .NET 10 / C# 14.
  • Cleaner collections, immutable DTOs, and value-centric modeling: Prefer collection expressions ([]), record, and readonly record struct to make data handling more explicit and safer.
  • More expressive, safer logic: Apply pattern matching (switch, list patterns, is extraction), Span<T> for slicing without allocations, raw string literals for readable multi-line content, and field for validated auto-properties.

Quick Start

Load this skill while writing or reviewing C# code and ask your agent to refactor a target class using C# 14 features (primary constructors, records, pattern matching, span usage, and raw strings) while preserving behavior.

Frequently Asked Questions about modern-csharp

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

FAQPage Schema
How do I refactor C# code to use primary constructors and records in .NET 10?

Refactoring C# code to use primary constructors and records in .NET 10 involves replacing verbose constructors and mutable DTOs with `public ClassName(dep1, dep2)` and `record` types to simplify class design and enforce immutability. This Skill applies these features to reduce boilerplate and improve data safety.

What is the best way to use Span<T> for slicing collections and strings in C# 14?

Using `Span<T>` for slicing in C# 14 provides a high-performance way to handle substrings and collection segments without allocating new memory on the heap. This Skill guides you in applying `Span<T>` slicing to eliminate allocation-heavy string and collection handling.

When should I use pattern matching and list patterns in C# 14?

Pattern matching and list patterns in C# 14 should be used to replace complex conditional logic with more expressive and safer syntax, utilizing `switch` expressions, list patterns, and `is` extraction. This Skill refactors verbose logic into clean, pattern-based implementations.

Does this modernization approach work with existing C# code reviews?

Yes, this modernization approach works during C# code reviews by identifying patterns like manual backing fields and mutable DTOs, then applying C# 14 features such as the `field` keyword and `readonly record struct` to improve readability and immutability while preserving behavior.

How do I simplify multi-line strings and auto-properties in C# 14?

To simplify multi-line strings and auto-properties in C# 14, use raw string literals for readable content and the `field` keyword for validated auto-properties. This Skill replaces manual backing fields and messy string literals with these modern C# features.

What are the limitations of using collection expressions and required members in C#?

Collection expressions and required members in C# require explicit anti-pattern avoidance rules to prevent misuse, such as incorrect initialization or improper dependency injection setup. This Skill provides guidance on safely applying `[]` expressions and `required` members while avoiding common pitfalls.