2025-10-27 09:00:38 +00:00
|
|
|
---
|
|
|
|
|
description: 'Guidelines for building C# applications'
|
|
|
|
|
applyTo: '**/*.cs'
|
|
|
|
|
---
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
# C# Development
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
## C# Instructions
|
|
|
|
|
- Always use the latest version C#, currently C# 13 features.
|
|
|
|
|
- Write clear and concise comments for each function.
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
## General Instructions
|
|
|
|
|
- Make only high confidence suggestions when reviewing code changes.
|
|
|
|
|
- Write code with good maintainability practices, including comments on why certain design decisions were made.
|
|
|
|
|
- Handle edge cases and write clear exception handling.
|
|
|
|
|
- For libraries or external dependencies, mention their usage and purpose in comments.
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
## Naming Conventions
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
- Follow PascalCase for component names, method names, and public members.
|
|
|
|
|
- Use camelCase for private fields and local variables.
|
|
|
|
|
- Prefix interface names with "I" (e.g., IUserService).
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
## Code Formatting
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
- Use CSharpier for all code formatting to ensure consistent style across the project.
|
|
|
|
|
- Install CSharpier globally: `dotnet tool install -g csharpier`
|
|
|
|
|
- Format files with: `dotnet csharpier format .`
|
2025-10-27 10:19:57 +00:00
|
|
|
- **ALWAYS run `dotnet csharpier format .` after making code changes before committing.**
|
2025-10-27 09:00:38 +00:00
|
|
|
- Configure your IDE to format on save using CSharpier.
|
|
|
|
|
- CSharpier configuration can be customized via `.csharpierrc` file in the project root.
|
|
|
|
|
- Trust CSharpier's opinionated formatting decisions to maintain consistency.
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
## Project Setup and Structure
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
- Guide users through creating a new .NET project with the appropriate templates.
|
|
|
|
|
- Explain the purpose of each generated file and folder to build understanding of the project structure.
|
|
|
|
|
- Demonstrate how to organize code using feature folders or domain-driven design principles.
|
|
|
|
|
- Show proper separation of concerns with models, services, and data access layers.
|
|
|
|
|
- Explain the Program.cs and configuration system in ASP.NET Core 9 including environment-specific settings.
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
## Nullable Reference Types
|
2025-10-13 11:52:18 +01:00
|
|
|
|
2025-10-27 09:00:38 +00:00
|
|
|
- Declare variables non-nullable, and check for `null` at entry points.
|
|
|
|
|
- Always use `is null` or `is not null` instead of `== null` or `!= null`.
|
|
|
|
|
- Trust the C# null annotations and don't add null checks when the type system says a value cannot be null.
|
|
|
|
|
|
|
|
|
|
## Testing
|
|
|
|
|
|
|
|
|
|
- Always include test cases for critical paths of the application.
|
|
|
|
|
- Guide users through creating unit tests.
|
|
|
|
|
- Do not emit "Act", "Arrange" or "Assert" comments.
|
|
|
|
|
- Copy existing style in nearby files for test method names and capitalization.
|
|
|
|
|
- Explain integration testing approaches for API endpoints.
|
|
|
|
|
- Demonstrate how to mock dependencies for effective testing.
|
|
|
|
|
- Show how to test authentication and authorization logic.
|
|
|
|
|
- Explain test-driven development principles as applied to API development.
|
|
|
|
|
|
|
|
|
|
## Performance Optimization
|
|
|
|
|
|
|
|
|
|
- Guide users on implementing caching strategies (in-memory, distributed, response caching).
|
|
|
|
|
- Explain asynchronous programming patterns and why they matter for API performance.
|
|
|
|
|
- Demonstrate pagination, filtering, and sorting for large data sets.
|
|
|
|
|
- Show how to implement compression and other performance optimizations.
|
|
|
|
|
- Explain how to measure and benchmark API performance.
|