modern csharp coding standards

Design Community

Skill notes

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

Reference Files

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

Core Principles

Immutability by Default - Use record types and init-only properties Type Safety - Leverage nullable reference types and value objects Modern Pattern Matching - Use switch expressions and patterns extensively Async Everywhere - Prefer async APIs with proper cancellation support Zero-Allocation Patterns - Use Span<T> and Memory<T> for performance-critical code

Records for Immutable Data (C 9+)

Use record types for DTOs, messages, events, and domain entities. When to use record class vs record struct: record class (default): Reference types, use for entities, aggregates, DTOs with multiple properties record struct: Value types, use for value objects (see next section)

Value Objects as readonly record struct

Value objects should always be readonly record struct for performance and value semantics. Use explicit conversions, never implicit operators. See value-objects-and-patterns.md for complete examples including multi-value objects, factory patterns, and the no-implicit-conversion rule.

Fluxly profile Runtime and permissions are inferred by Fluxly static checks, not author declarations or runtime test results.
Domain
Design
Author-declared agents
No explicit declaration found; this is not inferred or tested compatibility
Static check
88 / 100 · heuristic scan, not runtime safety proof
Runtime evidence
Not run; no isolated runtime test evidence is currently recorded
Author / version / license
@Aaronontheweb · no license declared
Token usage
Lean
Setup complexity
Guided setup
External API key
Not required
Operating systems
Unspecified (assume cross-platform)
Runtime requirements
No explicit requirements detected
Detected file/system behavior
  • Read-only
  • Write / modify
Network behavior
Local-only
Install commands
None (reference only)

Heads up: Tool permissions are not declared; actual access depends on the runtime.

Output preview modern-csharp-coding-standards.preview
# Error Handling: Result Type

For expected errors, use `Result<T, TError>` instead of exceptions. Use exceptions only for unexpected/system errors. See [composition-and-error-handling.md](composition-and-error-handling.md) for the full Result type implementation and usage examples. ---

Discussion

Powered by GitHub Discussions. Sign in with GitHub to comment, react, or subscribe.