Reporter | Jürgen Cruz (Jürgen_Cruz) |
---|---|
Created | Apr 10, 2018 10:40:35 PM |
Updated | Apr 10, 2018 10:40:35 PM |
Subsystem | No Subsystem |
Assignee | Unassigned |
Priority | Normal |
State | Submitted |
Type | Unspecified |
Fix version | No Fix versions |
Affected versions | No Affected versions |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
The following code is detected by resharper to be able to be refactored:
if (!request.ExecuteLatestVersion.HasValue || !request.ExecuteLatestVersion.Value) {
//do something
}
and it transforms to:
if (!request.ExecuteLatestVersion)
{
//do something
}
Which visual studio is complaining that it can't cast a bool? into a bool, which makes sense.
I'm not sure if it should actually be refactored into:
if (request.ExecuteLatestVersion != true)
{
//do something
}
Since both null and false are different than true. Although I wouldn't like that refactoring since it is no longer clear that it is a nullable flag and if someone changes that to "== false" it would have changed the logic by mistake.
I don't want to turn this check off since there are other merges that actually work and the resulting refactor is not ambiguous. for example:
if (p == null || p.Arguments == null)
refactoring into
if (p?.Arguments == null)
The p?.
actually lets the user know it is nullable. so it is not ambiguous.
And it is not only for negated (!
) expressions. The same happens with the following:
bool executeLatestVersion = request.ExecuteLatestVersion.HasValue && request.ExecuteLatestVersion.Value;
gets refactored to:
bool executeLatestVersion = request.ExecuteLatestVersion;
which again VS complains about.