Skip to content

Commit c688488

Browse files
committed
merge patterns
1 parent 060cf2d commit c688488

File tree

6 files changed

+18
-35
lines changed

6 files changed

+18
-35
lines changed

ReflectionAnalyzers/Helpers/Arguments.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ internal static class Arguments
8484

8585
if (conversion.IsIdentity || conversion.IsImplicit)
8686
{
87-
if (values[i] is MemberAccessExpressionSyntax memberAccess &&
88-
memberAccess.Name.Identifier.ValueText == "Value" &&
87+
if (values[i] is MemberAccessExpressionSyntax { Name.Identifier.ValueText: "Value" } &&
8988
semanticModel.TryGetSymbol(values[i], cancellationToken, out field) &&
9089
field == KnownSymbol.Missing.Value)
9190
{
@@ -95,8 +94,7 @@ internal static class Arguments
9594
continue;
9695
}
9796

98-
if (conversion.IsExplicit &&
99-
conversion.IsReference)
97+
if (conversion is { IsExplicit: true, IsReference: true })
10098
{
10199
continue;
102100
}

ReflectionAnalyzers/Helpers/Reflection/BindingFlagsExt.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ private static bool IsUsingStatic(SyntaxNode? location)
8989
static bool IsBindingFlags(UsingDirectiveSyntax @using)
9090
{
9191
return @using.StaticKeyword.IsKind(SyntaxKind.StaticKeyword) &&
92-
@using.Name is QualifiedNameSyntax qn &&
93-
qn.Right.Identifier.ValueText == "BindingFlags";
92+
@using.Name is QualifiedNameSyntax { Right.Identifier.ValueText: "BindingFlags" };
9493
}
9594
}
9695

ReflectionAnalyzers/Helpers/Reflection/GenericTypeArgument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Globalization;
88

99
[DebuggerDisplay("{this.MetadataName}")]
10-
internal struct GenericTypeArgument
10+
internal readonly struct GenericTypeArgument
1111
{
1212
internal readonly string MetadataName;
1313
internal readonly IReadOnlyList<GenericTypeArgument>? TypeArguments;

ReflectionAnalyzers/Helpers/Reflection/GenericTypeName.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ internal GenericTypeName(string metadataName, ImmutableArray<GenericTypeArgument
1616

1717
internal static GenericTypeName? TryParse(string text)
1818
{
19-
if (text.IndexOf('[') is var index &&
20-
index > 0)
19+
if (text.IndexOf('[') is var index and > 0)
2120
{
2221
var metadataName = text.Substring(0, index);
2322
if (TryParseArity(metadataName, out var arity) &&
@@ -34,8 +33,7 @@ internal GenericTypeName(string metadataName, ImmutableArray<GenericTypeArgument
3433
private static bool TryParseArity(string metadataName, out int result)
3534
{
3635
result = -1;
37-
return metadataName.IndexOf('`') is var i &&
38-
i > 0 &&
36+
return metadataName.IndexOf('`') is var i and > 0 &&
3937
i < metadataName.Length - 1 &&
4038
metadataName.Substring(i + 1) is { } substring &&
4139
!substring.EndsWith(" ", StringComparison.OrdinalIgnoreCase) &&

ReflectionAnalyzers/Helpers/Reflection/TypeArguments.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ private static bool IsMakeGeneric(InvocationExpressionSyntax invocation, Qualifi
158158
{
159159
return invocation.TryGetTarget(expected, semanticModel, cancellationToken, out var makeGeneric) &&
160160
makeGeneric.Parameters.TrySingle(out var parameter) &&
161-
parameter.IsParams &&
162-
parameter.Type is IArrayTypeSymbol arrayType &&
161+
parameter is { IsParams: true, Type: IArrayTypeSymbol arrayType } &&
163162
arrayType.ElementType == KnownSymbol.Type;
164163
}
165164

@@ -172,7 +171,7 @@ private bool SatisfiesConstraints(ExpressionSyntax expression, ITypeParameterSym
172171
switch (type)
173172
{
174173
case INamedTypeSymbol namedType
175-
when !namedType.Constructors.TryFirst(x => x.DeclaredAccessibility == Accessibility.Public && x.Parameters.IsEmpty, out _):
174+
when !namedType.Constructors.TryFirst(x => x is { DeclaredAccessibility: Accessibility.Public, Parameters.IsEmpty: true }, out _):
176175
case ITypeParameterSymbol { HasConstructorConstraint: false }:
177176
return false;
178177
}
@@ -278,9 +277,7 @@ bool TryGetEffectivelyValueType(ExpressionSyntax condition, out bool result)
278277
{
279278
switch (condition)
280279
{
281-
case MemberAccessExpressionSyntax { Expression: TypeOfExpressionSyntax { Type: IdentifierNameSyntax identifierName } } memberAccess
282-
when memberAccess.Name.Identifier.Text == "IsValueType" &&
283-
identifierName.Identifier.Text == candidate.Name:
280+
case MemberAccessExpressionSyntax { Expression: TypeOfExpressionSyntax { Type: IdentifierNameSyntax identifierName }, Name.Identifier.Text: "IsValueType" } when identifierName.Identifier.Text == candidate.Name:
284281
result = true;
285282
return true;
286283
case PrefixUnaryExpressionSyntax prefixUnary

ReflectionAnalyzers/NodeAnalzers/GetXAnalyzer.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ private static void Handle(SyntaxNodeAnalysisContext context)
6565
}
6666
}
6767

68-
if (member.Match == FilterMatch.Ambiguous &&
69-
member.ReflectedType is { })
68+
if (member is { Match: FilterMatch.Ambiguous, ReflectedType: not null })
7069
{
7170
context.ReportDiagnostic(
7271
Diagnostic.Create(
@@ -108,8 +107,7 @@ private static void Handle(SyntaxNodeAnalysisContext context)
108107
$" Expected: {flagsText}."));
109108
}
110109

111-
if (member.Match == FilterMatch.WrongMemberType &&
112-
member.Symbol is { })
110+
if (member is { Match: FilterMatch.WrongMemberType, Symbol: not null })
113111
{
114112
context.ReportDiagnostic(
115113
Diagnostic.Create(
@@ -132,8 +130,7 @@ private static void Handle(SyntaxNodeAnalysisContext context)
132130
callText));
133131
}
134132

135-
if (member.Match == FilterMatch.UseContainingType &&
136-
member.Symbol is { })
133+
if (member is { Match: FilterMatch.UseContainingType, Symbol: not null })
137134
{
138135
context.ReportDiagnostic(
139136
Diagnostic.Create(
@@ -164,8 +161,7 @@ private static void Handle(SyntaxNodeAnalysisContext context)
164161
nameText));
165162
}
166163

167-
if (member.Match == FilterMatch.ExplicitImplementation &&
168-
member.Symbol is { })
164+
if (member is { Match: FilterMatch.ExplicitImplementation, Symbol: not null })
169165
{
170166
context.ReportDiagnostic(
171167
Diagnostic.Create(
@@ -319,8 +315,7 @@ private static bool TryGetX(SyntaxNodeAnalysisContext context, out ReflectedMemb
319315

320316
private static bool HasMissingFlags(ReflectedMember member, Flags flags, [NotNullWhen(true)] out Location? location, [NotNullWhen(true)] out string? flagsText)
321317
{
322-
if (member.Symbol is { } symbol &&
323-
member.ReflectedType is { } &&
318+
if (member is { Symbol: { } symbol, ReflectedType: not null } &&
324319
Flags.TryGetExpectedBindingFlags(member.ReflectedType, symbol, out var correctFlags) &&
325320
member.Invocation?.ArgumentList is { } argumentList &&
326321
(member.Match == FilterMatch.Single || member.Match == FilterMatch.WrongFlags))
@@ -367,9 +362,7 @@ Location MissingFlagsLocation()
367362

368363
private static bool HasWrongFlags(ReflectedMember member, Flags flags, [NotNullWhen(true)] out Location? location, [NotNullWhen(true)] out string? flagText)
369364
{
370-
if (member.Match == FilterMatch.WrongFlags &&
371-
member.Symbol is { } &&
372-
member.ReflectedType is { } &&
365+
if (member is { Symbol: { }, ReflectedType: not null, Match: FilterMatch.WrongFlags } &&
373366
Flags.TryGetExpectedBindingFlags(member.ReflectedType, member.Symbol, out var correctFlags))
374367
{
375368
flagText = correctFlags.ToDisplayString(flags.Argument);
@@ -491,8 +484,7 @@ private static bool UsesNameOfWrongMember(ReflectedMember member, Name name, Syn
491484
NameOf.IsNameOf(argument, out var expression))
492485
{
493486
if (member.Match == FilterMatch.NoMatch ||
494-
(member.Match == FilterMatch.PotentiallyInvisible &&
495-
member.Symbol is not IMethodSymbol))
487+
member is { Match: FilterMatch.PotentiallyInvisible, Symbol: not IMethodSymbol })
496488
{
497489
nameText = $"\"{name.MetadataName}\"";
498490
location = argument.GetLocation();
@@ -541,8 +533,7 @@ private static bool IsPreferGetMemberThenAccessor(ReflectedMember member, Name n
541533
return TryGetEventAccessor(MemberName(eventSymbol), bindingFlags, out callText);
542534
}
543535
}
544-
else if (member.Match == FilterMatch.PotentiallyInvisible &&
545-
member.ReflectedType is { } &&
536+
else if (member is { Match: FilterMatch.PotentiallyInvisible, ReflectedType: not null } &&
546537
types.Argument is null &&
547538
flags.Explicit.HasFlagFast(BindingFlags.NonPublic))
548539
{
@@ -683,7 +674,7 @@ string MemberName(ISymbol associatedSymbol)
683674

684675
private static bool HasMissingTypes(ReflectedMember member, Types types, SyntaxNodeAnalysisContext context, [NotNullWhen(true)] out string? typesArrayText)
685676
{
686-
if ((member.Symbol as IMethodSymbol)?.AssociatedSymbol != null)
677+
if (member.Symbol is IMethodSymbol { AssociatedSymbol: not null })
687678
{
688679
typesArrayText = null;
689680
return false;

0 commit comments

Comments
 (0)