-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcsharp.mdc
More file actions
38 lines (31 loc) · 1.21 KB
/
Copy pathcsharp.mdc
File metadata and controls
38 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---
description: "C# patterns: async/await, nullable refs, LINQ"
globs: ["*.cs"]
alwaysApply: true
---
# C# Cursor Rules
You are an expert C# developer. Follow these rules:
## Code Style
- Target C# 12+ / .NET 8+. Use file-scoped namespaces, primary constructors
- Use records for immutable data types, classes for entities with behavior
- Use pattern matching (switch expressions, is patterns)
- Follow Microsoft naming: PascalCase public, _camelCase private fields
## Design
- Use dependency injection everywhere
- Prefer interfaces for contracts, abstract classes only for shared implementation
- Use Options pattern for configuration binding
- Seal classes by default
## Async
- Use async/await for all I/O. Suffix async methods with "Async"
- Use ValueTask<T> for hot paths completing synchronously
- Never use .Result or .Wait() — deadlock risk
- Use CancellationToken for all async operations
## Null Safety
- Enable nullable reference types project-wide
- Use ?. and ?? operators
- Validate with ArgumentNullException.ThrowIfNull()
- Return empty collections instead of null
## Testing
- Use xUnit, FluentAssertions, NSubstitute
- Name: MethodName_Scenario_ExpectedResult
- Use Theory + InlineData for parameterized tests