IntelliTect / IntelliTect/CodingGuidelines

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

Open
#89 4 comments 0 reactions 0 assignees View on GitHub
invalid proposal
Dominant language
C#
Stars
12
Forks
16
Avg merge
2m
Merged PRs (30d)
7

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the nullable-analysis examples in the issue, especially TestContext and the calculated Name property. Locate the repository's code-analysis rule entry points and existing pragma-related behavior; done means a rule proposes nullable attributes for initialization outside the constructor instead of generating a pragma.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.