Example #1
0
        public static SyntaxNode GetRootNode(this SyntaxNodeOrToken node)
        {
            SyntaxNode retVal = null;
            if (node.IsNode)
            {
                retVal = node.AsNode().GetRootNode();
            }
            else
            {
                retVal = node.AsToken().GetRootNode();
            }

            return retVal;
        }
Example #2
0
        // Helpers that return the language-specific (C# / VB) SyntaxKind of a language-agnostic
        // SyntaxNode / SyntaxToken / SyntaxTrivia.

        public static string GetKind(this SyntaxNodeOrToken nodeOrToken)
        {
            var kind = string.Empty;

            if (nodeOrToken.IsNode)
            {
                kind = nodeOrToken.AsNode().GetKind();
            }
            else
            {
                kind = nodeOrToken.AsToken().GetKind();
            }

            return kind;
        }
        // Helpers that return the language-sepcific (C# / VB) SyntaxKind of a language-agnostic
        // CommonSyntaxNode / CommonSyntaxToken / CommonSyntaxTrivia.

        public static string GetKind(this CommonSyntaxNodeOrToken nodeOrToken, string language)
        {
            var kind = string.Empty;

            if (nodeOrToken.IsNode)
            {
                kind = nodeOrToken.AsNode().GetKind(language);
            }
            else
            {
                kind = nodeOrToken.AsToken().GetKind(language);
            }

            return kind;
        }
Example #4
0
        public static NodeInfo GetNodeInfo(this SyntaxNodeOrToken nodeOrToken)
        {
            NodeInfo retVal = null;
            if (nodeOrToken.IsNode)
            {
                retVal = GetNodeInfo(nodeOrToken.AsNode());
            }
            else
            {
                retVal = GetNodeInfo(nodeOrToken.AsToken());
            }

            return retVal;
        }
        public static SyntaxNode GetNode(this SyntaxNodeOrToken nodeOrToken)
        {
            if (!nodeOrToken.IsNode) { throw new ArgumentException("expected node", nameof(nodeOrToken)); }

            return nodeOrToken.AsNode();
        }
        public static XElement ToXml(this SyntaxNodeOrToken node, SyntaxTree syntaxTree, XmlOptions options = null)
        {
            XElement xml = null;
            if (node.IsNode)
            {
                xml = ToXml(node.AsNode(), syntaxTree, options);
            }
            else
            {
                xml = ToXml(node.AsToken(), syntaxTree, options);
            }

            return xml;
        }