A member or parameter technically can contain null
, but it is not indicated whether callers should account for a null
value.
Resharper performs nullability analysis and issues warnings, such as missing or redundant null checks. Annotating members and parameters with nullability attributes improves the results of that analysis engine.
Annotate the target member or parameter with JetBrains.Annotations.CanBeNullAttribute
or JetBrains.Annotations.NotNullAttribute
.
There is no technical reason to suppress this warning.
The type C
defines members and parameters that can contain null
, which are not annotated.
namespace N
{
public class C
{
private string _f;
public string P => _f;
public string M(string p)
{
_f = p;
return p;
}
}
}
All members of the type C
that can contain null
are now annotated.
using JetBrains.Annotations;
namespace N
{
public class C
{
[CanBeNull] private string _f;
[CanBeNull] public string P => _f;
[NotNull] public string M([NotNull] string p)
{
_f = p;
return p;
}
}
}