Home Rules Refactorings Generators

BH0018: Prefer pattern matching over equality/inequality operators for null checks

Prefer pattern matching over equality/inequality operators for null checks.

Code with violation

public class TestClass {
    public void TestMethod(object? o) {
        if (o == null) {
            throw new ArgumentNullException();
        }
    }
}

Fixed Code

public class TestClass {
    public void TestMethod(object? o) {
        if (o is null) {
            throw new ArgumentNullException();
        }
    }
}

Copyright © 2025 Bluehill