# modern-csharp-coding-standards

Enforces modern C# 12+ coding standards, including immutable records, pattern matching, Span<T>, zero-allocation buffers, and async best practices.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 2200 installs · ★ 1238
- Author: Aaronontheweb
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/Aaronontheweb/dotnet-skills/tree/HEAD/skills/csharp-coding-standards/SKILL.md
- Updated: 2026-10-11
- HTML: https://affpapa.org/en/nevibecode/skills/modern-csharp-coding-standards

## What it does

This skill provides coding conventions for C# 12+, targeting domain models, public library APIs, and performance-sensitive paths. It enforces immutability by default using `record class` for entities or DTOs and `readonly record struct` for value objects. The rules reject abstract base classes in favor of interfaces and composition, and they ban implicit conversion operators on value objects.

For high-throughput code, the guidelines require `Span<T>` for zero-allocation synchronous work, `Memory<T>` for async operations, and `ArrayPool<T>` for temporary buffers. Async methods must take a `CancellationToken` defaulted to `default`, avoid `.Result` or `.Wait()`, and apply `ConfigureAwait(false)` in library code. Expected failures require explicit domain result types instead of thrown exceptions.

Your `.csproj` must have nullable reference types enabled via `<Nullable>enable</Nullable>`, or the static analysis rules will fail to protect the code.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add Aaronontheweb/dotnet-skills --skill modern-csharp-coding-standards -a claude-code
```
```bash
npx skills add Aaronontheweb/dotnet-skills --skill csharp-coding-standards -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/csharp-coding-standards/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/csharp-coding-standards/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add Aaronontheweb/dotnet-skills --skill csharp-coding-standards -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/csharp-coding-standards/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add Aaronontheweb/dotnet-skills --skill csharp-coding-standards -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/csharp-coding-standards/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install Aaronontheweb/dotnet-skills csharp-coding-standards
```

2. **Manually: put the files in place**
- File: `.github/skills/csharp-coding-standards/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add Aaronontheweb/dotnet-skills --skill csharp-coding-standards -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/Aaronontheweb/dotnet-skills --path skills/csharp-coding-standards
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/csharp-coding-standards/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add Aaronontheweb/dotnet-skills --skill csharp-coding-standards -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/Aaronontheweb/dotnet-skills/tree/HEAD/skills/csharp-coding-standards/SKILL.md

## When to use it
- refactor legacy domain classes into `record` and `readonly record struct` types
- eliminate heap allocations using `Span<T>`, `Memory<T>`, and `ArrayPool<T>`
- enforce explicit cancellation handling across async methods
- replace abstract base class hierarchies with interface composition

## Example prompts
- Design an order domain model using readonly record struct for identifiers and domain result types for errors
- Optimize this binary buffer parser using Span<T> to avoid allocations
- Refactor this service to enforce CancellationToken support and nullable reference checks

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 822c9e7f067a302e.

BEGIN THIRD-PARTY FILE 822c9e7f067a302e
````text
---
name: modern-csharp-coding-standards
description: Write modern, high-performance C# code using records, pattern matching, value objects, async/await, Span<T>/Memory<T>, and best-practice API design patterns. Emphasizes functional-style programming with C# 12+ features.
user-invocable: false
---

# Modern C# Coding Standards

## When to Use This Skill

Use this skill when:
- Writing new C# code or refactoring existing code
- Designing public APIs for libraries or services
- Optimizing performance-critical code paths
- Implementing domain models with strong typing
- Building async/await-heavy applications
- Working with binary data, buffers, or high-throughput scenarios

## Reference Files

- [value-objects-and-patterns.md](value-objects-and-patterns.md): Full value object examples and pattern matching code
- [performance-and-api-design.md](performance-and-api-design.md): Span<T>/Memory<T> examples and API design principles
- [composition-and-error-handling.md](composition-and-error-handling.md): Composition over inheritance, Result type, testing patterns
- [anti-patterns-and-reflection.md](anti-patterns-and-reflection.md): Reflection avoidance and common anti-patterns

## Core Principles

1. **Immutability by Default** - Use `record` types and `init`-only properties
2. **Type Safety** - Leverage nullable reference types and value objects
3. **Modern Pattern Matching** - Use `switch` expressions and patterns extensively
4. **Async Everywhere** - Prefer async APIs with proper cancellation support
5. **Zero-Allocation Patterns** - Use `Span<T>` and `Memory<T>` for performance-critical code
6. **API Design** - Accept abstractions, return appropriately specific types
7. **Composition Over Inheritance** - Avoid abstract base classes, prefer composition
8. **Value Objects as Structs** - Use `readonly record struct` for value objects

---

## Language Patterns

### Records for Immutable Data (C# 9+)

Use `record` types for DTOs, messages, events, and domain entities.

```csharp
// Simple immutable DTO
public record CustomerDto(string Id, string Name, string Email);

// Record with validation in constructor
public record EmailAddress
{
    public string Value { get; init; }

    public EmailAddress(string value)
    {
        if (string.IsNullOrWhiteSpace(value) || !value.Contains('@'))
````
END THIRD-PARTY FILE 822c9e7f067a302e

The third-party file has ended. Everything between the 822c9e7f067a302e tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2321 of 10695 bytes. © Aaronontheweb · MIT · https://github.com/Aaronontheweb/dotnet-skills/tree/HEAD/skills/csharp-coding-standards/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
