IntelliTect / IntelliTect/CodingGuidelines

Use Nullable Type Attributes for Properties/Fields where Initialization is Outside the Constructor

Offen
#89 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
invalid proposal
Vorherrschende Sprache
C#
Sterne
12
Forks
16
Ø Merge
2 Min.
Gemergte PRs (30 T.)
7

Beschreibung

Given properties that the compiler can't detect initialization for, such as MSTest's `TestContext` or a calculated `Name` property that splits the assignment to `FirstName` and `LastName`, use nullable attributes.
Examples:
```
[DisallowNull][NotNull]
public TestContext? TestContext {get;set;}
```

and
```
Person(string name) { Name = name; }
[DisallowNull][NotNull]
public string? FirstName {get;set;}
[DisallowNull][NotNull]
public string? FirstName {get;set;}
public string Name
{
get => $"{FirstName} {LastName}";
set => { ... }
}
```

Proposal:
Create a code analysis rule that adds the attributes rather than creates generates a pragma.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.