/// <summary> /// /// </summary> /// <param name="compIsInRight"></param> public void AddHighDigitCompare(CompareIsInRight compIsInRight) { if (isInRightDict.Count != totalDigit - 1) { throw new Exception("最高位比较规则必须在最后添加!"); } if (compIsInRight.Start != this.startNum || compIsInRight.End != this.endNum) { throw new Exception("最高位比较规则的开始数与结尾数不等于设置范围的开始与结尾数!"); } //添加项到字典 this.isInRightDict.Add(totalDigit, compIsInRight); ////设置最高位比较规则 //highDigitCompare = compIsInRight; }
/// <summary> /// 添加指定位数的比较规则(比较左右、奇偶) /// </summary> /// <param name="digitIndex">比较的位数,如个位为1,十位为2,百位为3,千位为4,依次类推,先添加个位规则</param> /// <param name="analysis"></param> /// <returns></returns> public void AddCompare(byte digitIndex, CompareIsInRight compIsInRight) { if (digitIndex > totalDigit) { throw new Exception("分析数组长度不能大于设置的位数!"); } if (digitIndex != isInRightDict.Count + 1) { throw new Exception("指定的位置错误,必须是当前比较字典的位置递加!\r\n首先添加个位规则,然后是十位、百位、千位等。"); } if (isInRightDict.ContainsKey(digitIndex)) { throw new Exception("指定的位置重复!"); } else { if (compIsInRight.Start > 9 || compIsInRight.End > 9) { throw new Exception("按位比较的开始数与结尾数不能大于9!"); } isInRightDict.Add(digitIndex, compIsInRight); } }
public bool IsInRight(uint num) { return(CompareIsInRight.IsInRight(num, Start, End, Mid)); }