Пример #1
0
        /// <summary>
        ///     Converts the string representation of a field highlighting options to the <see cref="HighlightedField" /> class.
        /// </summary>
        /// <param name="value">
        ///     Field highlighting options
        ///     <example>Text:250,3,TextFragments</example>
        /// </param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static bool TryParse(string value, out HighlightedField result)
        {
            result = null;

            var match = FieldOptionMatch.Match(value);

            if (!match.Success)
            {
                return(false);
            }

            var field = match.Groups["Field"].Value;

            if (string.IsNullOrWhiteSpace(field))
            {
                return(false);
            }

            int fragmentLength;

            if (!int.TryParse(
                    match.Groups["FragmentLength"].Value,
                    NumberStyles.None,
                    CultureInfo.InvariantCulture,
                    out fragmentLength))
            {
                return(false);
            }

            int fragmentCount;

            if (!int.TryParse(
                    match.Groups["FragmentCount"].Value,
                    NumberStyles.None,
                    CultureInfo.InvariantCulture,
                    out fragmentCount))
            {
                return(false);
            }

            var fragmentsField = match.Groups["FragmentsField"].Value;

            result = new HighlightedField(field, fragmentLength, fragmentCount, fragmentsField);

            return(true);
        }
Пример #2
0
        /// <summary>
        ///     Converts the string representation of a field highlighting options to the <see cref="HighlightedField" /> class.
        /// </summary>
        /// <param name="value">
        ///     Field highlighting options
        ///     <example>Text:250,3,TextFragments</example>
        /// </param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static bool TryParse(string value, out HighlightedField result)
        {
            result = null;

            var match = FieldOptionMatch.Match(value);

            if (!match.Success)
                return false;

            var field = match.Groups["Field"].Value;

            if (string.IsNullOrWhiteSpace(field))
                return false;

            int fragmentLength;

            if (!int.TryParse(
                match.Groups["FragmentLength"].Value,
                NumberStyles.None,
                CultureInfo.InvariantCulture,
                out fragmentLength))
                return false;

            int fragmentCount;

            if (!int.TryParse(
                match.Groups["FragmentCount"].Value,
                NumberStyles.None,
                CultureInfo.InvariantCulture,
                out fragmentCount))
                return false;

            var fragmentsField = match.Groups["FragmentsField"].Value;

            result = new HighlightedField(field, fragmentLength, fragmentCount, fragmentsField);

            return true;
        }