/// <summary> /// Initializes a new instance of the <see cref="BindingMarkup"/> class. /// </summary> public BindingMarkup() { Path = new BindingGetPropertyExpression(); }
/// <summary> /// Reads the expression. /// </summary> private Expressions.BindingPathExpression ReadExpression(List<BindingToken> tokens, ref int index) { if (!(tokens[index] is BindingTextToken)) { ThrowParserError("The expression must start with identifier.", tokens[index]); } var text = ((BindingTextToken)tokens[index]).Text; var binding = new BindingGetPropertyExpression() { PropertyName = text }; if (index + 1 < tokens.Count && tokens[index + 1] is BindingOpenIndexerToken) { var first = ((BindingTextToken)tokens[index + 2]).Text; if (tokens[index + 3] is BindingCloseIndexerToken) { // identifier[index] index += 3; int firstValue; if (!int.TryParse(first, out firstValue) || firstValue < 0) { ThrowParserError("The array index must be integer and must not be negative!", tokens[index + 2]); } binding.Indexer = new BindingArrayGetByIndexExpression() { Index = firstValue }; } else { // identifier[property=value] var second = ((BindingTextToken)tokens[index + 4]).Text; index += 5; binding.Indexer = new BindingArrayGetByKeyExpression() { KeyPropertyName = first, KeyValue = second }; } } if (index + 1 < tokens.Count) { if (tokens[index + 1] is BindingDotToken) { // identifier.identifier index += 2; binding.NextExpression = ReadExpression(tokens, ref index); return binding; } else if (tokens[index + 1] is BindingEqualsToken && binding.Indexer == null) { // identifier = expression index += 2; return new BindingParameterSetExpression() { ParameterName = text, Value = ReadExpression(tokens, ref index) }; } else if (tokens[index + 1] is BindingOpenBraceToken && binding.Indexer == null) { // identifier(expr, expr2...) index += 2; var expr = new BindingCallMethodExpression() { MethodName = text }; while (!(tokens[index] is BindingCloseBraceToken)) { if (expr.Arguments.Count > 0) { if (!(tokens[index] is BindingCommaToken)) { ThrowParserError("The binding parameters must be separated by comma.", tokens[index]); } index++; } var param = ReadExpression(tokens, ref index); expr.Arguments.Add(param); } index++; return expr; } } index++; return binding; }