Skip to content

Commit b951adc

Browse files
committed
Use GetConstructor.Match
1 parent 20d5223 commit b951adc

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

ReflectionAnalyzers/Helpers/Reflection/GetX.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,6 @@
1414
/// </summary>
1515
internal static class GetX
1616
{
17-
internal static bool TryGetConstructorInfo(MemberAccessExpressionSyntax memberAccess, SemanticModel semanticModel, CancellationToken cancellationToken, [NotNullWhen(true)] out IMethodSymbol? constructor)
18-
{
19-
if (TryFindInvocation(memberAccess, KnownSymbol.Type.GetConstructor, semanticModel, cancellationToken, out var invocation) &&
20-
TryMatchGetConstructor(invocation, semanticModel, cancellationToken, out var member, out _, out _) &&
21-
member is { Match: FilterMatch.Single, Symbol: IMethodSymbol match })
22-
{
23-
constructor = match;
24-
return true;
25-
}
26-
27-
constructor = null;
28-
return false;
29-
}
30-
3117
internal static bool TryGetNestedType(ExpressionSyntax expression, SemanticModel semanticModel, CancellationToken cancellationToken, [NotNullWhen(true)] out INamedTypeSymbol? type)
3218
{
3319
if (expression is MemberAccessExpressionSyntax memberAccess &&

ReflectionAnalyzers/NodeAnalzers/GetXAnalyzer.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,17 @@ private static bool TryGetX(SyntaxNodeAnalysisContext context, out ReflectedMemb
265265
return true;
266266
}
267267

268-
return GetX.TryMatchGetConstructor(candidate, context.SemanticModel, context.CancellationToken, out member, out flags, out types) ||
269-
GetX.TryMatchGetEvent(candidate, context.SemanticModel, context.CancellationToken, out member, out name, out flags) ||
268+
if (GetConstructor.Match(candidate, context.SemanticModel, context.CancellationToken) is { } getCtor)
269+
{
270+
member = getCtor.Member;
271+
name = default;
272+
flags = getCtor.Flags;
273+
types = getCtor.Types;
274+
return true;
275+
}
276+
277+
types = default;
278+
return GetX.TryMatchGetEvent(candidate, context.SemanticModel, context.CancellationToken, out member, out name, out flags) ||
270279
GetX.TryMatchGetField(candidate, context.SemanticModel, context.CancellationToken, out member, out name, out flags) ||
271280
GetX.TryMatchGetNestedType(candidate, context.SemanticModel, context.CancellationToken, out member, out name, out flags) ||
272281
GetX.TryMatchGetProperty(candidate, context.SemanticModel, context.CancellationToken, out member, out name, out flags, out types);

0 commit comments

Comments
 (0)