The idea of ​​checking code labeled "(when possible)" is simple: we decided not to offer a possible code conversion with default R # settings, since the resulting code can lead to reduced readability or complicate understanding. This decision about what to offer or not is made using special heuristics.
When we first introduced the suggestions and code transformations related to C # 6.0 and reviewed their results in large solutions available to us, we decided that there were almost ~ 2/3 cases of checks, such as "Merging sequential checks" / "Use zero distribution "should not be offered to do code conversions. For example, we believe that in the case of code:
if (node != null && node.IsValid()) { ... }
... are there no real benefits to using an operator ?. and introducing the operator "raised" operator==(bool, bool) over a value of type bool? :
if (node?.IsValid() == true) { ... }
Plus, different developers have different ideas on how to check a value of type bool? for true (some prefer to have ?? false instead, but that will make the resulting code even?.more ?? questionable ).
Thus, in the case above, the merging of sequential checks is definitely "possible", but we will not recommend it with the default settings R # (the correct default settings are a huge responsibility), as a result of which the user can see all cases by including "(when it is possible) "is the version of checking the same code. As far as I can tell, we are currently checking to see if the removed Boolean checks are in the “Collapse sequential checks” mode, other checks have more heuristics, for example:
if (stringBuilder != null) { // "Use null propagation" stringBuilder.Append("hello"); }
Code above cost suggesting to use a conditional call statement:
stringBuilder?.Append("hello");
When using a conditional call two or more times, it is doubtful ...
if (stringBuilder != null) { // no suggestion stringBuilder.Append("hello"); stringBuilder.Append("world"); stringBuilder.Append("!!!"); }
ps Contextual actions "Collapse sequential checks" / "For zero propagation" are always activated when conversion is possible, despite the status of the code checks and their severity.