title: How to get type of lambda in C# using Roslyn?
body: <p>I'm writing my codefixer with roslyn. I want it to work in such way:<br />
  Before:</p>
  <pre><code>IEnumerable&lt;int&gt; list = new List&lt;int&gt; {1, 2, 3, 4};
  list = list.Where(x =&gt; x%2 == 0);
  </code></pre>
  <p>After:</p>
  <pre><code>...
  IEnumerable&lt;int&gt; list = new List&lt;int&gt; {1, 2, 3, 4};
  list = list.Where(lambdaMethod);
  ...
  private static bool lamdaMethod(int x)
  {
      return x % 2 == 0;
  }
  </code></pre>
  <p>The problem is that I can't find the proper way to get return type for the method and type of argument.<br />
  My method from analyzer template:</p>
  <pre><code>public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
          {
              var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
  
              // TODO: Replace the following code with your own analysis, generating a CodeAction for each fix to suggest
              var diagnostic = context.Diagnostics.FirstOrDefault();
              var diagnosticSpan = diagnostic.Location.SourceSpan;
  
              // Find the type declaration identified by the diagnostic.
              var declaration = root.FindToken(diagnosticSpan.Start).Parent.AncestorsAndSelf()
                  .OfType&lt;LambdaExpressionSyntax&gt;().FirstOrDefault();
              if (declaration == null)
                  return;
              // Register a code action that will invoke the fix.
  
              context.RegisterCodeFix(
                  CodeAction.Create(
                      title: $&quot;{&quot;Just Title&quot;}&quot;,
                      createChangedDocument: c =&gt; MakeLambdaOptimization(context.Document, declaration, c),
                      equivalenceKey: nameof(CodeFixResources.CodeFixTitle)),
                  diagnostic);
          }
  </code></pre>
  <p>As you see, I'm working with <code>LambdaExpressionSyntax</code>. There are also <code>SimpleLambdaExpressionSyntax</code> and <code>ParenthesizedLambdaExpressionSyntax</code> which help me to get <code>ParameterSyntax</code>. In the <code>ParameterSyntax</code> I can find <code>Type</code>, but it's null and I get NullReferenceException.<br />
  I tried to get the whole type of lambda (e.g. <code>Func&lt;int, bool&gt;</code>), I guess it would help me. How can I do it? I've heard about SemanticModel, but I don't know how to use it</p>