コード例 #1
0
        /// <summary>
        /// Create a combination match based on an integer minimum should match value.
        /// </summary>
        /// <param name="minimumShouldMatch">The minimum number of optional clauses that must match.</param>
        /// <param name="value">The integer match value.</param>
        public CombinationMatch(int minimumShouldMatch, IntegerMatch value)
        {
            if (minimumShouldMatch <= 0)
            {
                throw new ArgumentOutOfRangeException("minimumShouldMatch", "CombinationMatch expects the minimumShouldMatch value to be a positive integer.");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value", "CombinationMatch integer match must be populated.");
            }

            _MinimumShouldMatch = minimumShouldMatch;
            _Value = value;
        }
コード例 #2
0
        private static SingleValueMatchBase BuildSingleValueMatch(string value)
        {
            SingleValueMatchBase match = null;
            if (value.Contains(PercentageMatch._PERCENTAGE))
            {
                Double percent = 0;
                string percentStr = value.Trim().TrimEnd(new char[] { '%' });
                if (Double.TryParse(percentStr, out percent))
                    match = new PercentageMatch(percent / (double)100);
                else
                    throw new ArgumentException("percentMatch", "Invalid percentage value: " + percentStr + ", from: " + value + ".");
            }
            else
            {
                int intValue = 0;
                string intStr = value.Trim();
                if (Int32.TryParse(intStr, out intValue))
                    match = new IntegerMatch(intValue);
                else
                    throw new ArgumentException("IntegerMatch", "Invalid integervalue value: " + value + ".");
            }

            return match;
        }