Skip to content

Commit ec494da

Browse files
committed
Always check for nameof invocations first
1 parent 9970303 commit ec494da

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/DendroDocs.Tool/Analyzers/InvocationsAnalyzer.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node)
5252
{
5353
var expression = this.GetExpressionWithSymbol(node);
5454

55-
if (Program.RuntimeOptions.VerboseOutput && semanticModel.GetSymbolInfo(expression).Symbol == null)
55+
if (semanticModel.GetConstantValue(node).HasValue && IsNameofExpression(node.Expression))
5656
{
57-
Console.WriteLine("WARN: Could not resolve type of invocation of the following block:");
58-
Console.WriteLine(node.ToFullString());
57+
// nameof is compiler sugar, and is actually a method we are not interrested in
5958
return;
6059
}
6160

62-
if (semanticModel.GetConstantValue(node).HasValue && string.Equals((node.Expression as IdentifierNameSyntax)?.Identifier.ValueText, "nameof", StringComparison.Ordinal))
61+
if (Program.RuntimeOptions.VerboseOutput && semanticModel.GetSymbolInfo(expression).Symbol is null)
6362
{
64-
// nameof is compiler sugar, and is actually a method we are not interrested in
63+
Console.WriteLine("WARN: Could not resolve type of invocation of the following block:");
64+
Console.WriteLine(node.ToFullString());
6565
return;
6666
}
6767

@@ -143,4 +143,9 @@ public override void VisitAssignmentExpression(AssignmentExpressionSyntax node)
143143

144144
base.VisitAssignmentExpression(node);
145145
}
146+
147+
private static bool IsNameofExpression(ExpressionSyntax expression)
148+
{
149+
return expression is IdentifierNameSyntax identifier && string.Equals(identifier.Identifier.ValueText, "nameof", StringComparison.Ordinal);
150+
}
146151
}

0 commit comments

Comments
 (0)