Esempio n. 1
0
 public VBToCSProjectContentsConverter(ConversionOptions conversionOptions, bool useProjectLevelWinformsAdjustments, IProgress <ConversionProgress> progress, CancellationToken cancellationToken)
 {
     _conversionOptions = conversionOptions;
     this._useProjectLevelWinformsAdjustments = useProjectLevelWinformsAdjustments;
     _progress          = progress;
     _cancellationToken = cancellationToken;
     OptionalOperations = new OptionalOperations(conversionOptions.AbandonOptionalTasksAfter, progress, cancellationToken);
 }
Esempio n. 2
0
        public CSToVBProjectContentsConverter(ConversionOptions conversionOptions, IProgress <ConversionProgress> progress, CancellationToken cancellationToken)
        {
            _progress          = progress;
            _cancellationToken = cancellationToken;
            OptionalOperations = new OptionalOperations(conversionOptions.AbandonOptionalTasksAfter, progress, cancellationToken);
            var vbCompilationOptions =
                (VisualBasicCompilationOptions)conversionOptions.TargetCompilationOptionsOverride ??
                VisualBasicCompiler.CreateCompilationOptions(conversionOptions.RootNamespaceOverride);

            if (conversionOptions.RootNamespaceOverride != null)
            {
                vbCompilationOptions = vbCompilationOptions.WithRootNamespace(conversionOptions.RootNamespaceOverride);
            }

            _vbCompilationOptions = vbCompilationOptions;
            _vbParseOptions       = VisualBasicCompiler.ParseOptions;
            RootNamespace         = conversionOptions.RootNamespaceOverride;
        }
Esempio n. 3
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));
        }
        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));
        }