title: Getting base class of a method invocation in Roslyn
body: <p>I can identify method calls and invocations inside the methods of each class of an application. However, how can I get on which class they are called or invoked?</p>
  
  <p>In the following code, for instance:</p>
  
  <pre><code>var methodDeclarations = classitem.DescendantNodes().OfType&lt;MethodDeclarationSyntax&gt;();
  foreach (var memmeth in methodDeclarations)
  {
  
      var varInvocations = memmeth.DescendantNodes().OfType&lt;InvocationExpressionSyntax&gt;();
      foreach (InvocationExpressionSyntax invoc in varInvocations)
      {
          Console.WriteLine("---- Invocations---");
          Console.WriteLine(invoc.Expression);  // output: b1.ADD
          Console.WriteLine(invoc.Expression.Parent.GetText()); // output: b1.ADD(2)
      }
  }
  </code></pre>
  
  <p>I can get, for example, as output "b1.ADD" and "b1.ADD(2)". What I need to extract from this is that ADD is called on b1 which is an instance of class B. How can I get this B class from the invocations in the code above? In other words, I need to tell to which class type this method belongs. How can I do that?</p>