public static MarkupExtensionParameterDescriptor Parse(string argsAsString) { MarkupExtensionParameterDescriptor arg = new MarkupExtensionParameterDescriptor(); int indexOfEqual = argsAsString.IndexOf('='); if (indexOfEqual < 0) { // Content Property arg.PropertyName = string.Empty; arg.Value = argsAsString.Trim(); } else { arg.PropertyName = argsAsString.Substring(0, indexOfEqual).Trim(); arg.Value = argsAsString.Substring(indexOfEqual + 1).Trim(); } return(arg); }
private static MarkupExtensionParameterDescriptor[] ParseArgs(string argsAsString) { string s = argsAsString.Trim(); List <string> args = new List <string>(); string currentArg = string.Empty; char currentChar; bool ignoreComma = false; bool skipWhiteSpace = true; bool isQuoting = false; int openedBracketCount = 0; for (int i = 0; i < s.Length; ++i) { if ((currentChar = s[i]) == '{' && !isQuoting) { ++openedBracketCount; currentArg += '{'; ignoreComma = true; skipWhiteSpace = true; } else if (currentChar == '}' && !isQuoting) { if (--openedBracketCount == 0) { ignoreComma = false; } currentArg += '}'; skipWhiteSpace = true; } else if (currentChar == '\'') { skipWhiteSpace = isQuoting; ignoreComma = (isQuoting = !isQuoting); currentArg += "'"; } else if (currentChar == ',' && !ignoreComma) { args.Add(currentArg); currentArg = string.Empty; skipWhiteSpace = true; } else if (!char.IsWhiteSpace(currentChar) || !skipWhiteSpace) { currentArg += currentChar; skipWhiteSpace = false; } } if (isQuoting) { throw new ArgumentException(string.Format("Unable to convert '{0}' to MarkupExtensionParameterDescriptor", argsAsString)); } if (!string.IsNullOrWhiteSpace(currentArg)) { args.Add(currentArg); } MarkupExtensionParameterDescriptor[] res = new MarkupExtensionParameterDescriptor[args.Count]; for (int i = 0; i < args.Count; ++i) { res[i] = MarkupExtensionParameterDescriptor.Parse(args[i]); } return(res); }