Reporter | ptrc (ptrc) |
---|---|
Created | Dec 5, 2011 10:03:14 PM |
Updated | Oct 8, 2018 4:39:20 PM |
Subsystem | Code Analysis - C# |
Assignee | Andrew Karpov (andrew.karpov) |
Priority | Major |
State | Open |
Type | Bug |
Fix version | Backlog |
Affected versions | 6.1, 6.1.1, 7.0, 7.0.1 |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
First, I really like your product. Please extend my thanks to your team for making my life so much easier.
I'm using 6.1 EAP, nightly build from December 5.
Consider the following:
Resharper suggests the code above could be changed to this:
The suggested code change has more than just a syntactical effect. From the c# specification:
The result is that the resharper code always returns a Decimal type, rendering the int.parse basically pointless.
I'm using 6.1 EAP, nightly build from December 5.
Consider the following:
Original
public object Example(string input)
{
object finalValue;
if (input.Contains('.'))
finalValue = Decimal.Parse(input);
else
finalValue = int.Parse(input);
return finalValue;
}
Resharper suggests the code above could be changed to this:
Resharper Suggestion
private object TestFull(string input)
{
object finalValue;
finalValue = input.Contains('.') ? Decimal.Parse(input) : int.Parse(input);
return finalValue;
}
The suggested code change has more than just a syntactical effect. From the c# specification:
If X and Y are the same type, then this is the type of the conditional expression.
- Otherwise, if an implicit conversion (Section 6.1) exists from X to Y, but not from Y to X, then Y is the type of the conditional expression.
- Otherwise, if an implicit conversion (Section 6.1) exists from Y to X, but not from X to Y, then X is the type of the conditional expression.
- Otherwise, no expression type can be determined, and a compile-time error occurs.
The result is that the resharper code always returns a Decimal type, rendering the int.parse basically pointless.