Skip to content

Commit 55430c0

Browse files
committed
chore(template): sync with dailydevops/dotnet-template [skip ci]
1 parent 7c41ded commit 55430c0

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
applyTo: '**/*.cs'
3+
4+
description: 'This file contains instructions for C# development.
5+
It includes guidelines for using GitHub Copilot, managing dependencies, and following coding standards.
6+
Ensure to follow the practices outlined in this file to maintain code quality and consistency.'
7+
---
8+
9+
# C# Development Instructions
10+
11+
## General
12+
13+
* The project MUST use the latest version C#, currently C# 13 features.
14+
* MUST follow standard C# coding conventions (naming, indentation, spacing).
15+
* MUST implement robust error handling with try-catch blocks and meaningful messages.
16+
* MUST write unit tests for all critical functionalities.
17+
* MUST always review AI-generated code for correctness, security, and performance.
18+
19+
## Code Style
20+
21+
Follow these C# coding conventions for consistency across the project.
22+
23+
* MUST use `var` when the type is obvious from the right side of the assignment.
24+
* MUST use `Argument.ThrowIfNull(x)` instead of `if (x == null) throw new ArgumentNullException(nameof(x))`, when nuget package `NetEvolve.Arguments` is referenced.
25+
* MUST use `ArgumentNullException.ThrowIfNull(x)` instead of `if (x == null) throw new ArgumentNullException(nameof(x))`, when nuget package `NetEvolve.Arguments` is not referenced.
26+
27+
## Formatting
28+
29+
Apply code-formatting style defined in `.editorconfig`.
30+
31+
* MUST prefer file-scoped namespace declarations and single-line using directives.
32+
* MUST insert a newline before the opening curly brace of any code block (e.g., after `if`, `for`, `while`, `foreach`, `using`, `try`, etc.).
33+
* MUST ensure that the final return statement of a method is on its own line.
34+
* MUST use pattern matching and switch expressions wherever possible.
35+
* MUST use `nameof` instead of string literals when referring to member names.
36+
* MUST ensure that XML doc comments are created for any public APIs. When applicable, include `<inheritdoc />` for derived members.
37+
38+
## Arrays and Collections
39+
40+
* MUST prefer `Enumerable.Empty<T>()` or `Array.Empty<T>()` over `null` returns.
41+
42+
## Nullable Reference Types
43+
44+
Declare variables non-nullable, and check for `null` at entry points.
45+
46+
* MUST always use `is null` or `is not null` instead of `== null` or `!= null`.
47+
* MUST trust the C# null annotations and don't add null checks when the type system says a value cannot be null.
48+
* MUST apply `NotNullAttribute` and other nullable attributes for any public APIs.
49+
50+
## Testing
51+
52+
* MUST prefer to use [TUnit](https://github.com/thomhurst/TUnit) with [Microsoft.Testing.Platform](https://learn.microsoft.com/dotnet/core/testing/microsoft-testing-platform-intro).
53+
* If TUnit is not available, MUST use [XUnit](https://xunit.net/).
54+
* MUST NOT emit `Act`, `Arrange` or `Assert` comments.
55+
* MUST NOT use any mocking framework at the moment.
56+
* MUST copy existing style in nearby files for test method names and capitalization.
57+
58+
## Build and test AI-generated code
59+
60+
1. Build from the root with `dotnet build <solutionfile>.slnx`.
61+
2. If that produces errors, fix those errors and build again. Repeat until the build is successful.
62+
3. Run tests with `dotnet test <solutionfile>.slnx`.
63+
4. If tests fail, analyze the failures and fix the code. Do not ignore failing tests.
64+
5. Verify that all new code has appropriate test coverage.
65+
6. Run a final build to ensure everything compiles successfully after all changes.
66+

0 commit comments

Comments
 (0)