- Home
- Skills
- Aaronontheweb
- Dotnet Skills
- Csharp Coding Standards
csharp-coding-standards_skill
- Shell
643
GitHub Stars
5
Bundled Files
3 weeks ago
Catalog Refreshed
2 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstart where the catalogue uses aiagentskills.
npx veilstart add skill aaronontheweb/dotnet-skills --skill csharp-coding-standards- anti-patterns-and-reflection.md8.6 KB
- composition-and-error-handling.md8.7 KB
- performance-and-api-design.md10.0 KB
- SKILL.md10.4 KB
- value-objects-and-patterns.md7.8 KB
Overview
This skill teaches modern, high-performance C# coding standards focused on C# 9+ and C# 12 features. It covers immutability with records, value-object patterns, advanced pattern matching, zero-allocation techniques, async/await best practices, and principled API design. The guidance is pragmatic and aimed at building safe, testable, and fast .NET code.
How this skill works
The skill inspects design choices and recommends patterns for domain modeling, API boundaries, and performance hotspots. It emphasizes readonly record structs for value objects, record types for immutable DTOs, exhaustive pattern matching for control flow, and explicit nullability. It also prescribes Span<T>/Memory<T> for buffer handling and async APIs that accept CancellationToken.
When to use it
- When creating or refactoring domain models and DTOs
- When designing public library or service APIs
- For performance-critical paths handling buffers or high throughput
- When implementing async workflows that need cancellation and composability
- When enforcing strong typing with value objects to avoid primitive abuse
Best practices
- Prefer immutable records and init-only properties for data shapes
- Model small, strongly-typed value objects as readonly record struct with no implicit conversions
- Use switch expressions, property and relational patterns to replace brittle if/else logic
- Expose async methods with CancellationToken and return Task/ValueTask appropriately
- Use Span<T>/Memory<T> and stack allocation in hot paths to avoid allocations
- Favor composition and interfaces over inheritance and abstract base classes
Example use cases
- Define CustomerId, OrderId, Money as readonly record struct to enforce domain invariants
- Refactor a mutable DTO to a record with validation in the constructor for safer creation
- Write a parsing routine using Span<byte> to process network buffers without allocations
- Design a public API that returns IReadOnlyList<T> and accepts abstractions rather than concrete types
- Implement service methods as async with explicit CancellationToken and propagate tokens through the call chain
FAQ
Implicit conversions hide boundary crossings and permit silent type coercion, defeating compile-time safety. Require explicit construction and access to preserve intent and validation.
When should I prefer record struct vs record class?
Use readonly record struct for small, immutable value objects requiring value semantics and low allocations. Use record class for entities, aggregates, and DTOs that benefit from reference semantics.