Пример #1
0
        public static async Task <SyntaxNode> ConvertCompilationTreeAsync(Document document,
                                                                          VisualBasicCompilation vbViewOfCsSymbols, Project vbReferenceProject, OptionalOperations optionalOperations, CancellationToken cancellationToken)
        {
            document = await document.WithExpandedRootAsync(cancellationToken);

            var compilation = await document.Project.GetCompilationAsync(cancellationToken);

            var tree = await document.GetSyntaxTreeAsync(cancellationToken);

            var semanticModel = compilation.GetSemanticModel(tree, true);
            var root          = await document.GetSyntaxRootAsync(cancellationToken) as CSS.CompilationUnitSyntax ??
                                throw new InvalidOperationException(NullRootError(document));

            var vbSyntaxGenerator = SyntaxGenerator.GetGenerator(vbReferenceProject);
            var numberOfLines     = tree.GetLineSpan(root.FullSpan).EndLinePosition.Line;

            var visualBasicSyntaxVisitor = new NodesVisitor(document, (CS.CSharpCompilation)compilation, semanticModel, vbViewOfCsSymbols, vbSyntaxGenerator, numberOfLines);
            var converted = (VBSyntax.CompilationUnitSyntax)root.Accept(visualBasicSyntaxVisitor.TriviaConvertingVisitor);

            return(optionalOperations.MapSourceTriviaToTargetHandled(root, converted, document));
        }
Пример #2
0
        public static async Task <SyntaxNode> ConvertCompilationTreeAsync(Document document,
                                                                          CSharpCompilation csharpViewOfVbSymbols, Project csharpReferenceProject,
                                                                          OptionalOperations optionalOperations, CancellationToken cancellationToken)
        {
            document = await document.WithExpandedRootAsync(cancellationToken);

            var root = await document.GetSyntaxRootAsync(cancellationToken) as VBSyntax.CompilationUnitSyntax ??
                       throw new InvalidOperationException(NullRootError(document));

            var compilation = await document.Project.GetCompilationAsync(cancellationToken);

            var tree = await document.GetSyntaxTreeAsync(cancellationToken);


            var csSyntaxGenerator        = SyntaxGenerator.GetGenerator(csharpReferenceProject);
            var semanticModel            = compilation.GetSemanticModel(tree, true);
            var visualBasicSyntaxVisitor = new
                                           DeclarationNodeVisitor(document, compilation, semanticModel, csharpViewOfVbSymbols, csSyntaxGenerator);
            var converted = (CSS.CompilationUnitSyntax) await root.AcceptAsync(visualBasicSyntaxVisitor.TriviaConvertingDeclarationVisitor);

            return(optionalOperations.MapSourceTriviaToTargetHandled(root, converted, document));
        }