public static MarkupExtensionInfo Parse(string input) { #region Parameter Checks if (!MarkupExtensionPattern.IsMatch(input)) { string msg = String.Format("{0} is not a MarkupExtension.", input); throw new InvalidOperationException(msg); } #endregion Parameter Checks var resultInfo = new MarkupExtensionInfo(); using (var reader = new StringReader(input)) { var parsingMode = MarkupExtensionParsingModeEnum.START; try { //Debug.Print("Parsing '{0}'", input); //Debug.Indent(); while (MarkupExtensionParsingModeEnum.END != parsingMode && MarkupExtensionParsingModeEnum.UNEXPECTED != parsingMode) { //Debug.Print(context.ToString()); //Debug.Indent(); switch (parsingMode) { case MarkupExtensionParsingModeEnum.START: parsingMode = reader.ReadMarkupExtensionStart(); break; case MarkupExtensionParsingModeEnum.MARKUP_NAME: parsingMode = reader.ReadMarkupName(resultInfo); break; case MarkupExtensionParsingModeEnum.NAME_VALUE_PAIR: parsingMode = reader.ReadNameValuePair(resultInfo); break; } //Debug.Unindent(); } } catch (Exception exp) { throw new InvalidDataException( String.Format("Cannot parse markup extension string:\r\n \"{0}\"", input), exp); } } return resultInfo; }
public static MarkupExtensionInfo Parse(string input) { if (!MarkupExtensionPattern.IsMatch(input)) { throw new InvalidOperationException($"{input} is not a MarkupExtension."); } var resultInfo = new MarkupExtensionInfo(); using (var reader = new StringReader(input)) { var parsingMode = MarkupExtensionParsingModeEnum.Start; try { //Debug.Print("Parsing '{0}'", input); //Debug.Indent(); while ((MarkupExtensionParsingModeEnum.End != parsingMode) && (MarkupExtensionParsingModeEnum.Unexpected != parsingMode)) { //Debug.Print(context.ToString()); //Debug.Indent(); switch (parsingMode) { case MarkupExtensionParsingModeEnum.Start: parsingMode = reader.ReadMarkupExtensionStart(); break; case MarkupExtensionParsingModeEnum.MarkupName: parsingMode = reader.ReadMarkupName(resultInfo); break; case MarkupExtensionParsingModeEnum.NameValuePair: parsingMode = reader.ReadNameValuePair(resultInfo); break; } //Debug.Unindent(); } } catch (Exception e) { throw new InvalidDataException($"Cannot parse markup extension string:\r\n \"{input}\"", e); } } return resultInfo; }