Skip to content

Commit adce5d7

Browse files
committed
Use GetField
1 parent 7368089 commit adce5d7

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

ReflectionAnalyzers/Helpers/Reflection/GetX.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ internal static bool TryMatchGetEvent(InvocationExpressionSyntax invocation, Sem
2121
return TryMatchGetX(invocation, KnownSymbol.Type.GetEvent, semanticModel, cancellationToken, out member, out name, out flags);
2222
}
2323

24-
/// <summary>
25-
/// Check if <paramref name="invocation"/> is a call to Type.GetField.
26-
/// </summary>
27-
internal static bool TryMatchGetField(InvocationExpressionSyntax invocation, SemanticModel semanticModel, CancellationToken cancellationToken, out ReflectedMember member, out Name name, out Flags flags)
28-
{
29-
return TryMatchGetX(invocation, KnownSymbol.Type.GetField, semanticModel, cancellationToken, out member, out name, out flags);
30-
}
31-
3224
/// <summary>
3325
/// Check if <paramref name="invocation"/> is a call to Type.GetNestedType.
3426
/// </summary>

ReflectionAnalyzers/Helpers/Reflection/Type.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,8 @@ private static bool TryGet(ExpressionSyntax expression, Recursion recursion, [No
160160
{
161161
switch (expression)
162162
{
163-
case MemberAccessExpressionSyntax { Expression: InvocationExpressionSyntax invocation, Name: { Identifier: { ValueText: "ReturnType" } } } memberAccess
164-
when GetMethod.Match(invocation, recursion.SemanticModel, recursion.CancellationToken) is { Single: { } single }:
165-
source = memberAccess;
166-
result = single.ReturnType;
167-
return true;
168163
case MemberAccessExpressionSyntax { Expression: InvocationExpressionSyntax invocation, Name: { Identifier: { ValueText: "FieldType" } } } memberAccess
169-
when GetField.Match(invocation, recursion.SemanticModel, recursion.CancellationToken) is { Single:{} single }:
164+
when GetField.Match(invocation, recursion.SemanticModel, recursion.CancellationToken) is { Single: { } single }:
170165
source = memberAccess;
171166
result = single.Type;
172167
return true;
@@ -177,6 +172,11 @@ when GetX.TryMatchGetProperty(invocation, recursion.SemanticModel, recursion.Can
177172
source = memberAccess;
178173
result = field.Type;
179174
return true;
175+
case MemberAccessExpressionSyntax { Expression: InvocationExpressionSyntax invocation, Name: { Identifier: { ValueText: "ReturnType" } } } memberAccess
176+
when GetMethod.Match(invocation, recursion.SemanticModel, recursion.CancellationToken) is { Single: { } single }:
177+
source = memberAccess;
178+
result = single.ReturnType;
179+
return true;
180180
case TypeOfExpressionSyntax typeOf:
181181
source = typeOf;
182182
return recursion.SemanticModel.TryGetType(typeOf.Type, recursion.CancellationToken, out result);

ReflectionAnalyzers/NodeAnalzers/GetXAnalyzer.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,12 @@ private static bool TryGetX(SyntaxNodeAnalysisContext context, out ReflectedMemb
256256
name = default;
257257
if (context.Node is InvocationExpressionSyntax candidate)
258258
{
259-
if (GetMethod.Match(candidate, context.SemanticModel, context.CancellationToken) is { } getMethod)
259+
if (GetField.Match(candidate, context.SemanticModel, context.CancellationToken) is { } getField)
260260
{
261-
member = getMethod.Member;
262-
name = getMethod.Name;
263-
flags = getMethod.Flags;
264-
types = getMethod.Types;
261+
member = getField.Member;
262+
name = getField.Name;
263+
flags = getField.Flags;
264+
types = default;
265265
return true;
266266
}
267267

@@ -274,9 +274,17 @@ private static bool TryGetX(SyntaxNodeAnalysisContext context, out ReflectedMemb
274274
return true;
275275
}
276276

277+
if (GetMethod.Match(candidate, context.SemanticModel, context.CancellationToken) is { } getMethod)
278+
{
279+
member = getMethod.Member;
280+
name = getMethod.Name;
281+
flags = getMethod.Flags;
282+
types = getMethod.Types;
283+
return true;
284+
}
285+
277286
types = default;
278287
return GetX.TryMatchGetEvent(candidate, context.SemanticModel, context.CancellationToken, out member, out name, out flags) ||
279-
GetX.TryMatchGetField(candidate, context.SemanticModel, context.CancellationToken, out member, out name, out flags) ||
280288
GetX.TryMatchGetNestedType(candidate, context.SemanticModel, context.CancellationToken, out member, out name, out flags) ||
281289
GetX.TryMatchGetProperty(candidate, context.SemanticModel, context.CancellationToken, out member, out name, out flags, out types);
282290
}

0 commit comments

Comments
 (0)