StyleChecker
IsNull
Summary
Use == null
or != null
instead of is null
.
Default severity
Info
Description
This rule reports diagnostic information of using is
pattern matching
with the null
constant literal.
Note that the default diagnostic severity of this analyzer is Information.
Code fix
The code fix provides an option replacing expression ... is null
and
!(... is null)
with ... == null
and ... != null
, respectively.
Remarks
Replacing the expression ... is null
with ... == null
, as well as replacing
!(... is null)
with ... != null
, can be a breaking change.
For more information, refer to
the description of EqualsNull code fix.
Example
Diagnostic
public void Method(object o, string s)
{
if (o is null)
{
⋮
}
if (!(s is null))
{
⋮
}
⋮
Code fix
public void Method(object o, string s)
{
if (o == null)
{
⋮
}
if (s != null)
{
⋮
}
⋮