How to get extension methods on Roslyn?
- by eestein
I need to list all extension methods found on the file.
This is what I'm doing so far (looks like it's working):
var methods = nodes.OfType<MethodDeclarationSyntax>();
var extensionMethods = methods.Where(m =>
m.Modifiers.Any(t => t.Kind == SyntaxKind.StaticKeyword)
&& m.ParameterList.Parameters.Any(p =>
p.Modifiers.Any(pm => pm.Kind == SyntaxKind.ThisKeyword)));
Even though I couldn't test all cases it looks like this is working.
But I was wondering if there was a more concise way to approach this solution.
Is there some sort of IsExtension or some SyntaxKind.ExtensionMethod? I took a look but could not find anything obvious, at least.
I'm using the latest Roslyn Sept/12