Beispiel #1
0
        private State ParseStart(Reader r, IList <ExpressionNode> nodes)
        {
            if (ParseNot(r))
            {
                nodes.Add(new LogicalNotNode());
                return(State.Start);
            }
            else if (ParseOpenBrace(r))
            {
                return(State.AttachedProperty);
            }
            else if (PeekOpenBracket(r))
            {
                return(State.Indexer);
            }
            else
            {
                var identifier = IdentifierParser.Parse(r);

                if (identifier != null)
                {
                    nodes.Add(new PropertyAccessorNode(identifier, _enableValidation));
                    return(State.AfterMember);
                }
            }

            return(State.End);
        }
Beispiel #2
0
        private State ParseAttachedProperty(CharacterReader r, List <ExpressionNode> nodes)
        {
            var(ns, owner) = ParseTypeName(r);

            if (r.End || !r.TakeIf('.'))
            {
                throw new ExpressionParseException(r.Position, "Invalid attached property name.");
            }

            var name = IdentifierParser.Parse(r);

            if (r.End || !r.TakeIf(')'))
            {
                throw new ExpressionParseException(r.Position, "Expected ')'.");
            }

            if (_typeResolver == null)
            {
                throw new InvalidOperationException("Cannot parse a binding path with an attached property without a type resolver. Maybe you can use a LINQ Expression binding path instead?");
            }

            var property = AvaloniaPropertyRegistry.Instance.FindRegistered(_typeResolver(ns, owner), name);

            nodes.Add(new AvaloniaPropertyAccessorNode(property, _enableValidation));
            return(State.AfterMember);
        }
Beispiel #3
0
        private State ParseElementName(CharacterReader r, List <ExpressionNode> nodes)
        {
            var name = IdentifierParser.Parse(r);

            if (name == null)
            {
                throw new ExpressionParseException(r.Position, "Element name expected after '#'.");
            }

            nodes.Add(new ElementNameNode(name));
            return(State.AfterMember);
        }
Beispiel #4
0
        private State ParseRelativeSource(CharacterReader r, List <ExpressionNode> nodes)
        {
            var mode = IdentifierParser.Parse(r);

            if (mode == "self")
            {
                nodes.Add(new SelfNode());
            }
            else if (mode == "parent")
            {
                Type ancestorType  = null;
                var  ancestorLevel = 0;
                if (PeekOpenBracket(r))
                {
                    var args = ArgumentListParser.Parse(r, '[', ']', ';');
                    if (args.Count > 2 || args.Count == 0)
                    {
                        throw new ExpressionParseException(r.Position, "Too many arguments in RelativeSource syntax sugar");
                    }
                    else if (args.Count == 1)
                    {
                        if (int.TryParse(args[0], out int level))
                        {
                            ancestorType  = null;
                            ancestorLevel = level;
                        }
                        else
                        {
                            var typeName = ParseTypeName(new CharacterReader(args[0]));
                            ancestorType = _typeResolver(typeName.ns, typeName.typeName);
                        }
                    }
                    else
                    {
                        var typeName = ParseTypeName(new CharacterReader(args[0]));
                        ancestorType  = _typeResolver(typeName.ns, typeName.typeName);
                        ancestorLevel = int.Parse(args[1]);
                    }
                }
                nodes.Add(new FindAncestorNode(ancestorType, ancestorLevel));
            }
            else
            {
                throw new ExpressionParseException(r.Position, "Unknown RelativeSource mode.");
            }

            return(State.AfterMember);
        }
Beispiel #5
0
        private State ParseBeforeMember(Reader r, IList <ExpressionNode> nodes)
        {
            if (ParseOpenBrace(r))
            {
                return(State.AttachedProperty);
            }
            else
            {
                var identifier = IdentifierParser.Parse(r);

                if (identifier != null)
                {
                    nodes.Add(new PropertyAccessorNode(identifier, _enableValidation));
                    return(State.AfterMember);
                }

                return(State.End);
            }
        }
Beispiel #6
0
        private static (string ns, string typeName) ParseTypeName(CharacterReader r)
        {
            string ns, typeName;

            ns = string.Empty;
            var typeNameOrNamespace = IdentifierParser.Parse(r);

            if (!r.End && r.TakeIf(':'))
            {
                ns       = typeNameOrNamespace;
                typeName = IdentifierParser.Parse(r);
            }
            else
            {
                typeName = typeNameOrNamespace;
            }

            return(ns, typeName);
        }