I need to parse a .cs file to look for a particular method. For instance, once the method named "X" is called, the analyzer should detect it.
How can detect that this particular node is a method?
Thanks in advance!
I need to parse a .cs file to look for a particular method. For instance, once the method named "X" is called, the analyzer should detect it.
How can detect that this particular node is a method?
Thanks in advance!
If you have a syntax node and semantic model for it you can try this:
// node – is your current syntax node
// semanticalModel – is your semantical model
ISymbol symbol = semanticModel.GetSymbolInfo(node).Symbol ?? semanticModel.GetDeclaredSymbol(node);
if(symbol.Kind == SymbolKind.Method)
{
// methodName – is a method's name that you are looking
if((symbol as IMethodSymbol).Name == methodName)
{
// you find your method
}
}
Also, you can determine that the current syntax node is your method without using the semantic model but it's a little harder than the way is above