public override async Task <Compilation> TransformCompilationAsync(Compilation oldCompilation, CancellationToken cancellationToken)
                {
                    var syntaxTrees = new List <SyntaxTree>(_documents.Length);

                    foreach (var document in _documents)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        syntaxTrees.Add(await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false));
                    }

                    return(oldCompilation.RemoveSyntaxTrees(syntaxTrees));
                }
Ejemplo n.º 2
0
        private static Compilation RemoveGeneratedSyntaxTrees(GeneratorDriverState state, Compilation compilation)
        {
            ArrayBuilder <SyntaxTree> trees = ArrayBuilder <SyntaxTree> .GetInstance();

            foreach (var generatorState in state.GeneratorStates)
            {
                foreach (var tree in generatorState.Trees)
                {
                    if (tree is object && compilation.ContainsSyntaxTree(tree))
                    {
                        trees.Add(tree);
                    }
                }
            }

            var comp = compilation.RemoveSyntaxTrees(trees);

            trees.Free();
            return(comp);
        }