private bool TryHandleAwait(AwaitExpressionSyntax @await) { if (@await == null) { return(false); } if (AsyncAwait.TryGetAwaitedInvocation(@await, this.semanticModel, this.cancellationToken, out InvocationExpressionSyntax invocation)) { this.awaits = true; var symbol = this.semanticModel.GetSymbolSafe(invocation, this.cancellationToken); if (symbol != null) { if (symbol.DeclaringSyntaxReferences.Length == 0) { this.AddReturnValue(invocation); } else { return(this.TryHandleInvocation(invocation)); } } return(true); } return(false); }
private void AddReturnValue(ExpressionSyntax value) { if (this.awaits) { if (AsyncAwait.TryAwaitTaskRun(value, this.semanticModel, this.cancellationToken, out ExpressionSyntax awaited)) { using (var walker = this.GetRecursive(awaited)) { if (walker.values.Count == 0) { this.values.Add(awaited); } else { foreach (var returnValue in walker.values) { this.AddReturnValue(returnValue); } } } return; } if (AsyncAwait.TryAwaitTaskFromResult(value, this.semanticModel, this.cancellationToken, out awaited)) { this.AddReturnValue(awaited); return; } if (this.search == Search.Recursive && value is AwaitExpressionSyntax @await) { value = @await.Expression; } } if (this.search == Search.Recursive) { if (value is InvocationExpressionSyntax invocation) { var method = this.semanticModel.GetSymbolSafe(invocation, this.cancellationToken); if (method == null || method.DeclaringSyntaxReferences.Length == 0) { this.values.Add(value); } else { using (var walker = this.GetRecursive(value)) { foreach (var returnValue in walker.values) { this.AddReturnValue(returnValue); } } } } else if (this.recursionLoop.Add(value) && this.semanticModel.IsEither <IParameterSymbol, ILocalSymbol>(value, this.cancellationToken)) { using (var assignedValues = AssignedValueWalker.Borrow(value, this.semanticModel, this.cancellationToken)) { if (assignedValues.Count == 0) { this.values.Add(value); } else { foreach (var assignment in assignedValues) { this.AddReturnValue(assignment); } } } } else { this.values.Add(value); } } else { this.values.Add(value); } }