public static SyntaxTree GetSyntaxTreeSynchronously(Document document, CancellationToken cancellationToken) { //TODO: Roslyn 2.0: use document.GetSyntaxTreeSynchronously() SyntaxTree syntaxTree; if (document.TryGetSyntaxTree(out syntaxTree)) return syntaxTree; return document.GetSyntaxTreeAsync(cancellationToken).GetAwaiter().GetResult(); }
static void ProcessDocument(Document document) { SyntaxTree syntaxTree; if (!document.TryGetSyntaxTree(out syntaxTree)) return; SyntaxNode rootNode = syntaxTree.GetRoot(); var throwClauses = rootNode.DescendantNodesAndSelf().OfType<ThrowStatementSyntax>(); var semanticModel = document.GetSemanticModelAsync().Result; foreach (var throwClause in throwClauses) { ProcessThrowClause(semanticModel, throwClause); } }