コード例 #1
0
 /// <summary>
 /// Returns new syntax trees where the inferred nullability has been inserted.
 /// </summary>
 public ParallelQuery <SyntaxTree> ConvertSyntaxTrees(CancellationToken cancellationToken)
 {
     return(compilation.SyntaxTrees.AsParallel().WithCancellation(cancellationToken).Select(syntaxTree => {
         var semanticModel = compilation.GetSemanticModel(syntaxTree);
         var rewriter = new InferredNullabilitySyntaxRewriter(semanticModel, typeSystem.GetMapping(syntaxTree), cancellationToken);
         var newRoot = rewriter.Visit(syntaxTree.GetRoot());
         return syntaxTree.WithRootAndOptions(newRoot, syntaxTree.Options);
     }));
 }
コード例 #2
0
        /// <summary>
        /// Invokes the callback with the new syntax trees where the inferred nullability has been inserted.
        /// </summary>
        public Statistics ConvertSyntaxTrees(CancellationToken cancellationToken, Action <SyntaxTree> action)
        {
            object     statsLock  = new object();
            Statistics statistics = new Statistics();

            Parallel.ForEach(compilation.SyntaxTrees,
                             new ParallelOptions {
                CancellationToken = cancellationToken
            },
                             syntaxTree => {
                var semanticModel = compilation.GetSemanticModel(syntaxTree);
                var rewriter      = new InferredNullabilitySyntaxRewriter(semanticModel, typeSystem, typeSystem.GetMapping(syntaxTree), cancellationToken);
                var newRoot       = rewriter.Visit(syntaxTree.GetRoot());
                action(syntaxTree.WithRootAndOptions(newRoot, syntaxTree.Options));
                lock (statsLock) {
                    statistics.Update(rewriter.Statistics);
                }
            });
            return(statistics);
        }