Static code analyzer for C#
$ dotnet add package ThinkMeta.CodeAnalysis.CSharpStatic code analyzer for C#
ThinkMeta.CodeAnalysis is a static code analyzer for C# projects, built on Roslyn. It helps developers identify code issues, enforce coding standards, and improve code quality automatically.
Description:
Warns when using == null or != null for null checks.
Reason:
Pattern matching (is null, is not null) is preferred for clarity and future-proofing code.
How to fix:
Replace == null with is null, and != null with is not null.
Exceptions:
Null checks using == null or != null inside expression trees (e.g., lambdas assigned to Expression<Func<...>>) are not reported by this diagnostic, as pattern matching is not supported in expression trees.
Example:
// Bad
if (obj == null) { }
// Good
if (obj is null) { }
Example (no warning):
using System.Linq.Expressions;
Expression<Func<object, bool>> expr = o => o == null; // No diagnostic