public override void VisitInvocationExpression()

in dotnet/CSharpSourceGraphExtraction/MethodUseInformationCollector.cs [72:113]


        public override void VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            var invocationSymbol = _graph.SemanticModel.GetSymbolInfo(node).Symbol as IMethodSymbol;

            if (invocationSymbol == null) return;
            string methodName = invocationSymbol.Name;
            if (invocationSymbol.Name.IndexOf('<') != -1)
            {
                methodName = methodName.Substring(0, methodName.IndexOf('<'));
            }
            string invocationExpression;
            if (node.Expression is MemberAccessExpressionSyntax memberAccess)
            {
                invocationExpression = memberAccess.Name.ToString();
            } else
            {
                invocationExpression = node.Expression.ToString();
            }
            if (invocationExpression.IndexOf('<') != -1)
            {
                invocationExpression = invocationExpression.Substring(0, invocationExpression.IndexOf('<'));
            }

            if (!invocationExpression.EndsWith(methodName))
            {
                // Heuristic: this may happen when an implicit conversion exits e.g. "string x = SomeObjectRetType()"
                // or an invocation of an anonymous function, such as a lambda, when the method name is "Invoke"
                if (methodName != "Invoke")
                {
                    Console.WriteLine($"Rejecting Invocation because expression name and symbol do not match: {methodName} -> {node.Expression}");
                }
                return; 
            }
            else if (node.ArgumentList.ToString().Contains("__arglist"))
            {
                Console.WriteLine($"Rejecting Invocation because it contains an __arglist: {node}");
                return;
            }

            RecordInvocation(invocationSymbol, node, node.ArgumentList);
            base.VisitInvocationExpression(node);
        }