Exemplo n.º 1
0
        /// <summary>
        /// Tries to parse the provided string into a <see cref="Grouping"/>.
        /// </summary>
        /// <param name="stringToParse">The string to try and parse.</param>
        /// <param name="depthLevel">How many levels deep this grouping is.</param>
        /// <param name="result">The resulting <see cref="Grouping"/></param>
        /// <returns>True if the provided string is valid.</returns>
        internal static bool TryParseGrouping(string stringToParse, int depthLevel, out Grouping result)
        {
            result = null;

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

            if (stringToParse.StartsWith("(") && stringToParse.EndsWith(")"))
            {
                // Strip off the opening and closing parens
                stringToParse = stringToParse.Remove(0, 1);
                stringToParse = stringToParse.Remove(stringToParse.Length - 1, 1);
            }

            // We can't end with comma (since it's used for listing).
            if (stringToParse.EndsWith(","))
            {
                return false;
            }

            try
            {
                result = new Grouping(stringToParse, depthLevel);
            }
            catch (Exception)
            {
                // Since it's a TryParse swallow the exception.  This is really bad practice, but for now it's fine.
                return false;
            }

            return true;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Attempts to add a child grouping based on the provided string.
 /// </summary>
 /// <param name="childGroupingAsString"></param>
 public void AddChildGrouping(string childGroupingAsString)
 {
     Grouping grouping;
     if (Grouping.TryParseGrouping(childGroupingAsString, this.depthLevel + 1, out grouping))
     {
         this.childGrouping = grouping;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Tries to parse the provided string into a <see cref="Grouping"/>. Assumes a depth-level of 0.
 /// </summary>
 /// <param name="stringToParse">The string to try and parse.</param>
 /// <param name="result">The resulting <see cref="Grouping"/></param>
 /// <returns>True if the provided string is valid.</returns>
 internal static bool TryParseGrouping(string stringToParse, out Grouping result)
 {
     return TryParseGrouping(stringToParse, 0, out result);
 }