Skip to content

Commit

Permalink
fix: handle property invocation expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
cslong committed Jun 30, 2022
1 parent 9abd787 commit 98deb39
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/CTA.Rules.Update/VisualBasicActionsRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,32 @@ public override SyntaxNode VisitExpressionStatement(ExpressionStatementSyntax no

public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
{
var symbol = (IMethodSymbol)SemanticHelper.GetSemanticSymbol(node, _semanticModel, _preportSemanticModel);
var newNode = base.VisitInvocationExpression(node);
var symbol = SemanticHelper.GetSemanticSymbol(node, _semanticModel, _preportSemanticModel);

if (symbol == null)
{
return node;
}

var prefix = symbol.IsExtensionMethod ? symbol.ReceiverType?.ToString() ?? "" : symbol.ContainingType?.ToString() ?? "";
var nodeKey = $"{prefix}.{symbol.Name}({string.Join(", ", symbol.Parameters.Select(p => p.Type))})";
var nodeKey = "";
if (symbol is IMethodSymbol)
{
var methodSymbol = (IMethodSymbol)symbol;
var prefix = methodSymbol.IsExtensionMethod
? methodSymbol.ReceiverType?.ToString() ?? ""
: methodSymbol.ContainingType?.ToString() ?? "";
nodeKey =
$"{prefix}.{symbol.Name}({string.Join(", ", methodSymbol.Parameters.Select(p => p.Type))})";
}
else if (symbol is IPropertySymbol)
{
var propertySymbol = (IPropertySymbol)symbol;
var prefix = propertySymbol.ContainingType?.ToString() ?? "";
nodeKey =
$"{prefix}.{symbol.Name}({string.Join(", ", propertySymbol.Parameters.Select(p => p.Type))})";
}

var newNode = base.VisitInvocationExpression(node);

foreach (var action in _allActions.OfType<InvocationExpressionAction<InvocationExpressionSyntax>>())
{
Expand Down

0 comments on commit 98deb39

Please sign in to comment.