Reporter | Clinton Sheppard (clinton) |
---|---|
Created | Feb 22, 2008 10:01:08 PM |
Updated | Apr 13, 2018 6:28:40 PM |
Resolved | Apr 13, 2018 6:28:40 PM |
Subsystem | Code Analysis |
Assignee | Ilya Ryzhenkov (orangy) |
Priority | Normal |
State | Fixed |
Type | Feature |
Fix version | Unidentified prior version |
Affected versions | No Affected versions |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
// incorrect
public DateTime GetAdjustedDate(int months)
{
DateTime result = DateTime.Now;
result.AddMonths(-months); // modified value not stored to a variable, this line has no apparent value
return result;
}
// correct
public DateTime GetAdjustedDate(int months)
{
DateTime now = DateTime.Now;
result = now.AddMonths(-months);
return result;
}
Resharper could detect the case were results to instance methods that do not change the instance are not captured in a variable.
Similar methods are not hard to find:
string foo = "bar";
foo.ToUpper(); // modified value not stored to a variable, this line has no apparent value
return foo;
public DateTime GetAdjustedDate(int months)
{
DateTime result = DateTime.Now;
result.AddMonths(-months); // modified value not stored to a variable, this line has no apparent value
return result;
}
// correct
public DateTime GetAdjustedDate(int months)
{
DateTime now = DateTime.Now;
result = now.AddMonths(-months);
return result;
}
Resharper could detect the case were results to instance methods that do not change the instance are not captured in a variable.
Similar methods are not hard to find:
string foo = "bar";
foo.ToUpper(); // modified value not stored to a variable, this line has no apparent value
return foo;