Skip to content

Commit 4b2cec6

Browse files
committed
Walk more
1 parent f06102d commit 4b2cec6

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

ReflectionAnalyzers.Tests/REFL001CastReturnValueTests/CodeFix.ConstructorInfoInvoke.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public C(int i)
4545
}
4646

4747
[TestCase("info.Invoke(new object[] { 1 })")]
48-
//[TestCase("info?.Invoke(new object[] { 1 })")]
49-
//[TestCase("info!.Invoke(new object[] { 1 })")]
48+
[TestCase("info?.Invoke(new object[] { 1 })")]
49+
[TestCase("info!.Invoke(new object[] { 1 })")]
5050
public static void Walk(string expression)
5151
{
5252
var code = @"

ReflectionAnalyzers/Helpers/Reflection/GetX.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,22 @@ internal static class GetX
1919
{
2020
InvocationExpressionSyntax invocation
2121
=> invocation,
22-
PostfixUnaryExpressionSyntax { RawKind: (int)SyntaxKind.SuppressNullableWarningExpression, Operand: InvocationExpressionSyntax invocation }
23-
=> invocation,
22+
PostfixUnaryExpressionSyntax { RawKind: (int)SyntaxKind.SuppressNullableWarningExpression, Operand: { } operand }
23+
=> operand switch
24+
{
25+
InvocationExpressionSyntax invocation => invocation,
26+
IdentifierNameSyntax identifierName => FindInvocation(identifierName, semanticModel, cancellationToken),
27+
_ => null,
28+
},
2429
MemberAccessExpressionSyntax { Expression: { } inner }
2530
=> FindInvocation(inner, semanticModel, cancellationToken),
26-
MemberBindingExpressionSyntax { Parent.Parent: ConditionalAccessExpressionSyntax { Expression: InvocationExpressionSyntax invocation } }
27-
=> invocation,
31+
MemberBindingExpressionSyntax { Parent.Parent: ConditionalAccessExpressionSyntax { Expression: { } expression } }
32+
=> expression switch
33+
{
34+
InvocationExpressionSyntax invocation => invocation,
35+
IdentifierNameSyntax identifierName => FindInvocation(identifierName, semanticModel, cancellationToken),
36+
_ => null,
37+
},
2838
IdentifierNameSyntax identifierName
2939
when semanticModel.TryGetSymbol(identifierName, cancellationToken, out ILocalSymbol? local) &&
3040
AssignedValue.FindSingle(local, semanticModel, cancellationToken) is { } value

0 commit comments

Comments
 (0)