Reputation: 89
I am trying to use roslyn to get the return statements of a method, for that I am using this:
var returns = methods.DescendantNodes().OfType<ReturnStatementSyntax>();
That works, it gives me all the return statements. But now, I want to get all the returns ignoring the ones inside lambda expressions.
How can I do that?
Is there any property that indicates that?
Upvotes: 0
Views: 299
Reputation: 564
I am not sure but you can try something similar like this:
method.DescendantNodes().OfType<ReturnStatementSyntax>().Where(
rs => !(rs.AncestorsAndSelf().OfType<LambdaExpressionSyntax>().Any())
);
I hope this will solve your problem.
Upvotes: 5