コード例 #1
0
        /// <summary>
        /// Create a combination match based on a percentation minimum should match value.
        /// </summary>
        /// <param name="minimumShouldMatch">The minimum number of optional clauses that must match.</param>
        /// <param name="value">The percentage match value.</param>
        public CombinationMatch(int minimumShouldMatch, PercentageMatch 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 percentage 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;
        }