Must-share information (formatted with Markdown):
- which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
- what are you trying to achieve
- what have you tried so far to achieve this
environment info : Sonarqube 7.9.1
Hi, I’m creating my own custom rule using roslyn API.
I’m curious about accessing parameter’s instance inheritance value of method.
First, as I attached some picture, I have to get parameter’s instance inheritance value of method.
What I want to get the value is “HISDTOBase” through SelectCPRRecords method in the picture.
Now, I could get the value “CPRRecords_IN” in SelectCPRRecords method. I’m using MethodDeclarationSyntax.ParameterList.Parameters to get method’s value. but I couldn’t get that method parameter’s instance inheritance value.
I already try to looked it up this problem from Syntax Visualizer. and I tried several times to get the value.
How can I get method’s parameter instance’s inheritance value?
==== my simple code sample ====
Initialize override method
- context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.CompilationUnit);
AnalyzeNode method - private void AnalyzeNode(SyntaxNodeAnalysisContext context)
{
var rootNode = (CompilationUnitSyntax)context.Node;
MemberDeclarationSyntax memberNode = rootNode.Members[0];
var classNode = (ClassDeclarationSyntax)memberNode.Members[0];
foreach(var member in classNode.Members)
{
string memberType = member.Kind().ToString();
if (memberType.Equals(“MethodDeclaration”))
{
SH1302 sh1302 = new SH1302(context, (MethodDeclarationSyntax) member);
}
}
}
public class SH1302
{
public SH1302(SyntaxNodeAnalysisContext context, MethodDeclarationSyntax methodNode)
{
var temp = methodNode.ParameterList.Parameters;
foreach(var tem in temp)
{
// I tried below, but not working
//var met = tem.Identifier;
//var parent = met.Parent;
//var e = tem.Type;
//var child = e.ChildNodes();
}
}
}
I really need your help. Thank you for reading my question.
I appreciate any of your suggestion.
