modern-csharp-coding-standards

Enforce modern C# 12+ coding standards for performance and error handling.

Updated Jan 29, 2024
One-click install
npx skills add https://github.com/riandeoliveira/aspnet-template --skill modern-csharp-coding-standards-riandeoliveira
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: modern-csharp-coding-standards
Source: https://github.com/riandeoliveira/aspnet-template/tree/main/.claude/skills/csharp-coding-standards
Command: npx skills add https://github.com/riandeoliveira/aspnet-template --skill modern-csharp-coding-standards-riandeoliveira

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It prevents slow, error-prone, and inconsistent C# codebases by providing clear, modern standards for architecture, correctness, and performance-critical implementations.

Core Features & Use Cases

  • Modern language guidance: Applies C# 12+ practices such as records, pattern matching, nullable reference types, and idiomatic async/await.
  • Value objects & domain modeling: Enforces readonly record struct for value objects to make invalid states unrepresentable.
  • High-performance API patterns: Guides Span<T>/Memory<T>, zero-allocation approaches, and proper method signatures (including CancellationToken and streaming with IAsyncEnumerable).
  • Error handling & composition: Promotes composition over inheritance and uses domain-specific Result types for expected failures.
  • Anti-pattern prevention: Discourages reflection-based mapping (e.g., AutoMapper) and other common pitfalls that hide bugs until runtime.

Quick Start

Use this skill to review or generate a refactored version of your C# code to match modern C# coding standards and performance best practices.

Frequently Asked Questions about modern-csharp-coding-standards

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

FAQPage Schema
How do I implement modern C# coding standards for high-performance APIs?

To implement value objects in C#, use `readonly record struct` to make invalid states unrepresentable. This modern C# approach ensures domain models remain immutable, structurally sound, and protected against runtime mapping bugs commonly introduced by reflection-based tools.

What is the best way to handle errors in async C# workflows?

The best way to handle errors in async C# workflows is by using domain-specific Result types for expected failures instead of throwing exceptions. This approach enforces predictable error handling and promotes composition over inheritance for robust async/await operations.

Does this C# guidance support zero-allocation buffer-oriented logic?

Yes, this C# guidance supports zero-allocation buffer-oriented logic by applying Span<T> and Memory<T> patterns. It enforces modern method signatures and proper cancellation token handling to ensure high-throughput operations perform predictably without unnecessary memory allocations.

Why should I avoid reflection-based mapping in C# domain models?

You should avoid reflection-based mapping in C# domain models because it hides bugs until runtime. Modern C# standards discourage tools like AutoMapper and instead promote using `readonly record struct` and pattern matching to make invalid states unrepresentable at compile time.

Can I use C# 12 records and pattern matching for domain modeling?

Yes, you can use C# 12 records and pattern matching for domain modeling. Modern C# standards enforce these features alongside nullable reference types to create safe, maintainable domain models that prevent invalid states and improve architectural correctness.