NotNullMigration.Analyzer
0.1.0
dotnet add package NotNullMigration.Analyzer --version 0.1.0
NuGet\Install-Package NotNullMigration.Analyzer -Version 0.1.0
<PackageReference Include="NotNullMigration.Analyzer" Version="0.1.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="NotNullMigration.Analyzer" Version="0.1.0" />
<PackageReference Include="NotNullMigration.Analyzer"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add NotNullMigration.Analyzer --version 0.1.0
#r "nuget: NotNullMigration.Analyzer, 0.1.0"
#:package NotNullMigration.Analyzer@0.1.0
#addin nuget:?package=NotNullMigration.Analyzer&version=0.1.0
#tool nuget:?package=NotNullMigration.Analyzer&version=0.1.0
NotNullMigration.Analyzer
A Roslyn analyzer that helps migrate your C# projects to nullable-enabled (<Nullable>enable</Nullable>) by detecting nullable properties and fields that are only ever assigned non-nullable values.
Installation
dotnet add package NotNullMigration.Analyzer
Example
The analyzer detects nullable members that can safely be made non-nullable:
// Before — NOTNULL001: 'Name' is declared nullable but is only assigned non-nullable values
public class User
{
public string? Name { get; set; }
public User(string name)
{
Name = name;
}
public void UpdateName(string newName)
{
Name = newName;
}
}
Apply the code fix to remove the unnecessary ?:
// After — no diagnostic
public class User
{
public string Name { get; set; }
public User(string name)
{
Name = name;
}
public void UpdateName(string newName)
{
Name = newName;
}
}
Applying Code Fixes
IDE (Visual Studio / Rider / VS Code)
Hover over the warning and use the lightbulb (Quick Actions) to apply "Remove nullable annotation". You can also fix all occurrences at once via Fix All in Document / Project / Solution.
CLI
Use dotnet format to apply all fixes from the command line:
# Fix all NOTNULL001 warnings in the solution
dotnet format analyzers --diagnostics NOTNULL001 --severity warn
Rules
| Rule ID | Category | Severity | Description |
|---|---|---|---|
| NOTNULL001 | Design | Warning | Nullable member can be made non-nullable |
How It Works
The analyzer uses the Roslyn IOperation API to track all assignments to nullable properties and fields across the entire compilation. At CompilationEnd, it reports any member that was only assigned non-nullable values.
For interface properties, it aggregates across all implementations — reporting only when every implementation assigns exclusively non-nullable values.
For a detailed breakdown of all edge cases, see docs/architecture.md.
Configuration
You can change the severity or disable the rule in your .editorconfig:
[*.cs]
# Disable the rule
dotnet_diagnostic.NOTNULL001.severity = none
# Or change to error
dotnet_diagnostic.NOTNULL001.severity = error
Contributing
See CONTRIBUTING.md for build instructions and how to submit changes.
License
This project is licensed under the MIT License — see LICENSE for details.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 34 | 3/10/2026 |