I'm trying to get type and constructor info out of an ObjectCreationExpressionSyntax element.
I first need to assess that the created instance is an ArgumentException or a class that derives from it. Then, I need to get the ConstructorInfo (System.Reflection) that's being used.
public override void Initialize(AnalysisContext context)
{
context.RegisterSyntaxNodeAction(c =>
{
var local = c.Node as ObjectCreationExpressionSyntax;
if (local == null)
return;
ArgumentSyntax paramNameArgument;
bool conditionsAreMet;
// the code that's required to get both the Type and ConstructorInfo instances would go here
if (conditionsAreMet)
{
c.ReportDiagnostic(Diagnostic.Create(Rule, paramNameArgument.GetLocation()));
}
}, SyntaxKind.ObjectCreationExpression);
}
The ObjectCreationExpressionSyntax has a Type property, which I'm pretty sure will be the starting point. However, I don't quite understand how am I supposed to extract anything from it.
Any guidance would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire