I am trying to get the parameters list of a class method using Roslyn and noticed a strange behavior that Roslyn considers and returns a Lambda parameter used inside the body of the method as as one of the parameters of the method, which cause an error in my code. Why does Roslyn consider a lambda parameter as of the method's parameters?
Here is the code:
var paramDeclaratons = memmeth.DescendantNodes().OfType<ParameterSyntax>();
foreach (var mempara in paramDeclaratons)
{
String paramType = mempara.Type.ToFullString().Trim(); //Here it crashes with System.NullReferenceException because Lambda returns no type!
The code which is parsed:
public void Method1(RequestId requestId)
{
...
var packetsToKeep = this.queuedPackets.Where(p => p.RequestId != requestId)
p is returned as one of the parameters of Method1 with no type