Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use the null-conditional operator instead of a ternary null check
Replace `x != null ? x.Y : null` with `x?.Y` — the null-conditional operator is shorter and expresses the same intent.
Bad example
| 1 | var v = node != null ? node.GetAttributeValue("x") : null; |
Explanation (EN)
The null-conditional operator expresses guarded access without repeating the receiver.
Objašnjenje (HR)
Good example
| 1 | var v = node?.GetAttributeValue("x"); |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
For a C# nullable receiver tested before one member access, check that the receiver is evaluated once and the resulting nullable type matches the surrounding assignment.
Exceptions / Tradeoffs (EN)
Do not apply this C# equivalence to JavaScript when null must remain distinct from undefined; check overloaded comparisons and side-effecting receivers.