nullable-shorthand
What it does
Section titled “What it does”Reports Nullable<int> or System.Nullable<int>, which is int?. The check is by name: a type of your own called Nullable is reported too. It is not reported in using aliases, in nameof, in typeof(Nullable<>), and before a member access (Nullable<int>.Equals). The fix writes int?.
Why it matters
Section titled “Why it matters”int? is the form of the language and is shorter. One spelling makes the nullable types easy to find, and Nullable<T> stays for the places where the generic name is the point.
Example
Section titled “Example”class A { int a, b; Nullable<int> n = (long)1 < 2 ? null : null; void F(object o, int i) { var f = delegate (int x) { return x; }; var g = null == o || 1 < i;...class A { int a, b; int? n = (long)1 < 2 ? null : null; void F(object o, int i) { var f = delegate (int x) { return x; }; var g = null == o || 1 < i;...Configuration
Section titled “Configuration”csharp: lint: rules: nullable-shorthand: warn # off (default), warn, errorEnabled by the presets: csharp/stylecop, csharp/roslynator.
Suppress one line with sudsy-disable-next-line nullable-shorthand in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| Roslynator | RCS1020 |
full |
| StyleCop | SA1125 |
full |