Esempio n. 1
0
        /// <summary>
        /// Gets all occurrances of a node type in the AST.
        /// </summary>
        /// <param name="nodeType">The node type to look for.</param>
        /// <param name="recurse">If <c>true</c>, the search process will proceed recursively inside nodes, otherwise only the first level will be inspected.</param>
        /// <returns>A <see cref="SyntaxNode"/>.</returns>
        public IEnumerable <SyntaxNode> LocateAll(Type nodeType, bool recurse = true)
        {
            ValidateInputType(nodeType);

            List <SyntaxNode> nodes = new List <SyntaxNode>();
            var astExecutor         = new ASTWalkerNodeTypeOperationExecutor(this.Root, nodeType, (node) => nodes.Add(node), recurse);

            astExecutor.Start();

            return(nodes.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the last occurrance of a node type in the AST.
        /// </summary>
        /// <param name="nodeType">The node type to look for.</param>
        /// <param name="recurse">If <c>true</c>, the search process will proceed recursively inside nodes, otherwise only the first level will be inspected.</param>
        /// <returns>A <see cref="SyntaxNode"/>.</returns>
        public SyntaxNode LocateLast(Type nodeType, bool recurse = true)
        {
            ValidateInputType(nodeType);

            List <SyntaxNode> nodes = new List <SyntaxNode>();
            var astExecutor         = new ASTWalkerNodeTypeOperationExecutor(this.Root, nodeType, (node) => nodes.Add(node), recurse);

            astExecutor.Start();

            return(nodes.Count > 0 ? nodes[nodes.Count - 1] : null);
        }