我正在使用刚刚发布的 Resharper (2016.2.2) 版本重新锐化我的解决方案
它标记了这行代码:
ReportRunnerConstsAndUtils.ConvertValueToAppropriateTypeAndAssign(totalPackagesCell, packages);
...暗示我应该“作为扩展方法调用”
如果我默认,它会将该行更改为:
totalPackagesCell.ConvertValueToAppropriateTypeAndAssign(packages);
这是否更好?如果是这样,怎么做?为什么?
这是被调用的方法,它位于“ConstsAndUtils”类中:
// Adapted from https://stackoverflow.com/questions/26483496/is-it-possible-to-ignore-excel-warnings-when-generating-spreadsheets-using-epplu
public static void ConvertValueToAppropriateTypeAndAssign(this ExcelRangeBase range, object value)
{
string strVal = value.ToString();
if (!String.IsNullOrEmpty(strVal))
{
decimal decVal;
double dVal;
int iVal;
if (decimal.TryParse(strVal, out decVal))
range.Value = decVal;
if (double.TryParse(strVal, out dVal))
range.Value = dVal;
else if (Int32.TryParse(strVal, out iVal))
range.Value = iVal;
else
range.Value = strVal;
}
else
range.Value = null;
}