コード例 #1
0
ファイル: Program.cs プロジェクト: piotrosz/RoslynChart
        private static CommonSyntaxNode TransformRootCSharp(Roslyn.Compilers.CSharp.SyntaxNode originalRoot)
        {
            var comments = originalRoot.DescendantTrivia().Where(t => t.Kind == Roslyn.Compilers.CSharp.SyntaxKind.SingleLineCommentTrivia);
            var newRoot  = originalRoot.ReplaceTrivia(comments, (t1, t2) => Roslyn.Compilers.CSharp.SyntaxTriviaList.Empty);

            return(newRoot);
        }
コード例 #2
0
        private static VB.StructuredTriviaSyntax CreateBadDirective(CS.SyntaxNode node, NodeVisitor visitor)
        {
            var leadingTrivia = node.GetFirstToken(includeSkipped: true).LeadingTrivia.SelectMany(visitor.VisitTrivia).Where(t => t.Kind != VB.SyntaxKind.EndOfLineTrivia);
            var trailingTrivia = node.GetLastToken(includeSkipped: true).TrailingTrivia.SelectMany(visitor.VisitTrivia).Where(t => t.Kind != VB.SyntaxKind.EndOfLineTrivia);

            var comment = CreateCouldNotBeConvertedComment(node.ToString(), typeof(VB.StatementSyntax));
            leadingTrivia = leadingTrivia.Concat(
                VB.Syntax.CommentTrivia(comment));

            var token = VB.Syntax.Token(TriviaList(leadingTrivia), VB.SyntaxKind.HashToken, trailing: TriviaList(trailingTrivia), text: "");
            return VB.Syntax.DirectiveTrivia(VB.Syntax.BadDirective(token), VB.Syntax.Token(VB.SyntaxKind.StatementTerminatorToken, text: ""));
        }
コード例 #3
0
        private static VB.StatementSyntax CreateBadStatement(CS.SyntaxNode node, NodeVisitor visitor)
        {
            var leadingTrivia = node.GetFirstToken(includeSkipped: true).LeadingTrivia.SelectMany(visitor.VisitTrivia);
            var trailingTrivia = node.GetLastToken(includeSkipped: true).TrailingTrivia.SelectMany(visitor.VisitTrivia);

            var comment = CreateCouldNotBeConvertedComment(node.ToString(), typeof(VB.StatementSyntax));
            leadingTrivia = leadingTrivia.Concat(
                VB.Syntax.CommentTrivia(comment));

            var token = VB.Syntax.Token(TriviaList(leadingTrivia), VB.SyntaxKind.EmptyToken, trailing: TriviaList(trailingTrivia));
            return VB.Syntax.EmptyStatement(token);
        }
コード例 #4
0
        private static string Convert(
            IText text,
            CS.SyntaxNode node,
            IDictionary<string, string> identifierMap,
            bool convertStrings)
        {
            if (node is CS.StatementSyntax)
            {
                var nodeVisitor = new NodeVisitor(text, identifierMap, convertStrings);
                var statementVisitor = new StatementVisitor(nodeVisitor, text);
                var vbStatements = statementVisitor.Visit(node);

                return string.Join(Environment.NewLine, vbStatements.Select(s => VB.SyntaxExtensions.NormalizeWhitespace(s)));
            }
            else
            {
                var visitor = new NodeVisitor(text, identifierMap, convertStrings);
                var vbNode = visitor.Visit(node);

                return VB.SyntaxExtensions.NormalizeWhitespace(vbNode).ToFullString();
            }
        }
コード例 #5
0
 public override VB.SeparatedSyntaxList <VB.StatementSyntax> DefaultVisit(CS.SyntaxNode node)
 {
     throw new NotImplementedException();
 }