How to get extension methods on Roslyn?
Posted
by
eestein
on Stack Overflow
See other posts from Stack Overflow
or by eestein
Published on 2012-12-07T17:02:07Z
Indexed on
2012/12/07
17:03 UTC
Read the original article
Hit count: 269
roslyn-ctp
|roslyn
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
© Stack Overflow or respective owner