我在VS2013 RC中选择“分析>分析代码克隆解决方案”,希望它能够实现这两种方法:
private static char GetBarcodeChecksumWithLegacyCode(string barcodeWithoutCzechSum)
{
Contract.Requires(!string.IsNullOrWhiteSpace(barcodeWithoutCzechSum));
if (barcodeWithoutCzechSum.Length > 6)
{
int a = 0;
int b = 0;
int j = barcodeWithoutCzechSum.Length - 1;
int i = j;
while (i >= 0)
{
a = a + barcodeWithoutCzechSum[i] - 48;
i = i - 2;
}
j = barcodeWithoutCzechSum.Length - 2;
i = j;
while (i >= 0)
{
b = b + barcodeWithoutCzechSum[i] - 48;
i = i - 2;
}
a = 3 * a + b;
b = a % 10;
if (b != 0) b = 10 - b;
var ch = (char)(48 + b);
return ch;
}
return ' ';
}
public static string GetBarcodeChecksum(string barcode)
{
int oddTotal;
int oddTotalTripled;
int evenTotal;
// Which positions are odd or even depend on the length of the barcode,
// or more specifically, whether its length is odd or even, so:
if (isStringOfEvenLen(barcode))
{
oddTotal = sumInsideOrdinals(barcode);
oddTotalTripled = oddTotal * 3;
evenTotal = sumOutsideOrdinals(barcode);
}
else
{
oddTotal = sumOutsideOrdinals(barcode);
oddTotalTripled = oddTotal * 3;
evenTotal = sumInsideOrdinals(barcode);
}
int finalTotal = oddTotalTripled + evenTotal;
int modVal = finalTotal % 10;
int czechSum = 10 - modVal;
if (czechSum == 10)
{
return "0";
}
return czechSum.ToString();
}
......功能相同。第一个是神秘的,第二个(对我而言,也许是因为它是我写的那个)很简单。但该工具并未将其视为“代码克隆”。
是因为我的方法调用其他方法,即isStringOfEvenLen(),sumInsideOrdinals()和sumOutsideOrdinals()?