private async Task <IMethodSymbol> GetMethodSymbolAsync(string code, string name) { var(model, root) = await IMethodSymbolExtensionsTests.ParseFileAsync(code); foreach (var method in root.DescendantNodes().OfType <MethodDeclarationSyntax>()) { if (model.GetDeclaredSymbol(method) is IMethodSymbol methodNode && methodNode.Name == name) { return(methodNode); } } return(null); }
private async Task <IMethodSymbol> GetMethodSymbolAsync(string file, string name) { var results = await IMethodSymbolExtensionsTests.ParseFileAsync(file); foreach (var method in results.Item2.DescendantNodes().OfType <MethodDeclarationSyntax>()) { var methodNode = results.Item1.GetDeclaredSymbol(method) as IMethodSymbol; if (methodNode != null && methodNode.Name == name) { return(methodNode); } } return(null); }
private async Task <IMethodSymbol> GetMethodReferenceSymbolAsync(string file, string name) { var results = await IMethodSymbolExtensionsTests.ParseFileAsync( file, MetadataReference.CreateFromFile(typeof(BusinessBase <>).Assembly.Location)); foreach (var invocation in results.Item2.DescendantNodes().OfType <InvocationExpressionSyntax>()) { var methodNode = results.Item1.GetSymbolInfo(invocation); if (methodNode.Symbol != null && methodNode.Symbol.Name == name) { return(methodNode.Symbol as IMethodSymbol); } } return(null); }
private async Task <IMethodSymbol> GetMethodReferenceSymbolAsync(string code, string name, Type type) { var(model, root) = await IMethodSymbolExtensionsTests.ParseFileAsync( code, MetadataReference.CreateFromFile(type.Assembly.Location)); foreach (var invocation in root.DescendantNodes().OfType <InvocationExpressionSyntax>()) { var symbol = model.GetSymbolInfo(invocation); var methodSymbol = symbol.Symbol as IMethodSymbol; if (methodSymbol == null && symbol.CandidateReason == CandidateReason.OverloadResolutionFailure && symbol.CandidateSymbols.Length > 0) { methodSymbol = symbol.CandidateSymbols[0] as IMethodSymbol; } if (methodSymbol?.Name == name) { return(methodSymbol); } } return(null); }