Helper for accessing namespaces in AST.
Inheritance: Helper
コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NamespaceASTWalker"/> class.
        /// </summary>
        protected NamespaceASTWalker(CSharpSyntaxNode node)
        {
            var namespaceSyntaxNode = node as NamespaceDeclarationSyntax;
            if (namespaceSyntaxNode == null)
            {
                throw new ArgumentException(
                    string.Format("Specified node is not of type {0}",
                    typeof(NamespaceDeclarationSyntax).Name));
            }

            this.node = node;
            NamespaceDeclaration namespaceHelper = new NamespaceDeclaration(namespaceSyntaxNode);

            this.module = ModuleTranslationUnit.Create(
                IdentifierTranslationUnit.Create(namespaceHelper.Name));
        }
コード例 #2
0
        private void RetrieveEmptyNamespaces()
        {
            new MultiPurposeASTWalker(this.newNode,
                astNode => astNode as NamespaceDeclarationSyntax != null,
                delegate (SyntaxNode astNode)
                {
                    var namespaceNode = astNode as NamespaceDeclarationSyntax;
                    var helper = new NamespaceDeclaration(namespaceNode);

                    if (helper.Types.Count() == 0)
                    {
                        this.removableNamespaces.Add(namespaceNode);
                    }
                })
                .Start();
        }