Example #1
0
        /// <summary>
        /// Converts the string representation of a range to the equivalent range.
        /// </summary>
        /// <param name="input">The range string to parse.</param>
        /// <param name="boundaryParser">The parser to parse the boundary value.</param>
        /// <param name="result">
        /// The range that will contain the parsed value.
        /// If the method returns <c>true</c>, result contains a valid range.
        /// If the method returns <c>false</c>, result will be <see langword="null"/>. </param>
        /// <returns><c>true</c> if the parse operation was successful; otherwise, <c>false</c>.</returns>
        public static bool TryParse(string input, BoundaryParser <T> boundaryParser, out Range <T> result)
        {
            bool   includeLowerBound, includeUpperBound;
            string lowerBoundText, upperBoundText;

            result = null;
            ParseRange(input, out includeLowerBound, out includeUpperBound, out lowerBoundText, out upperBoundText);
            T lowerBound, upperBound;

            if (!boundaryParser(lowerBoundText, out lowerBound) || !boundaryParser(upperBoundText, out upperBound))
            {
                return(false);
            }
            result = new Range <T>(lowerBound, upperBound, includeLowerBound, includeUpperBound);
            return(true);
        }
Example #2
0
 static Range()
 {
     _parser    = CreateParser();
     _tryParser = CreateTryParser();
 }