Skip to content

Commit 59eee19

Browse files
authored
Add an entry on the coding style for primary constructors (#116723)
1 parent 38c8e8f commit 59eee19

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

docs/coding-guidelines/coding-style.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The general rule we follow is "use Visual Studio defaults".
3333
- Using braces is always accepted, and required if any block of an `if`/`else if`/.../`else` compound statement uses braces or if a single statement body spans multiple lines.
3434
- Braces may be omitted only if the body of *every* block associated with an `if`/`else if`/.../`else` compound statement is placed on a single line.
3535
19. Make all internal and private types static or sealed unless derivation from them is required. As with any implementation detail, they can be changed if/when derivation is required in the future.
36+
20. Primary constructor parameters should be named like parameters, using `camelCase` and not prefixed with `_`. For example, `public ObservableLinkedList(IEnumerable<T> items)` instead of `public ObservableLinkedList(IEnumerable<T> _items)`. However, if the type is not sufficiently small such that it is easy to see where the parameters are used, then the primary constructor parameters should be assigned to fields prefixed with `_` (e.g. `private readonly IEnumerable<T> _items = item;`).
3637

3738
An [EditorConfig](https://editorconfig.org "EditorConfig homepage") file (`.editorconfig`) has been provided at the root of the runtime repository, enabling C# auto-formatting conforming to the above guidelines.
3839

0 commit comments

Comments
 (0)