Skip to content

Commit 39334d6

Browse files
committed
simplify patterns
1 parent f4b7c89 commit 39334d6

37 files changed

Lines changed: 145 additions & 145 deletions

IDisposableAnalyzers/Analyzers/AssignmentAnalyzer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private static void Handle(SyntaxNodeAnalysisContext context)
5656

5757
private static bool IsReassignedWithCreated(AssignmentExpressionSyntax assignment, SyntaxNodeAnalysisContext context)
5858
{
59-
if (assignment.Right is IdentifierNameSyntax { Identifier: { ValueText: "value" } } &&
59+
if (assignment.Right is IdentifierNameSyntax { Identifier.ValueText: "value" } &&
6060
assignment.FirstAncestor<AccessorDeclarationSyntax>() is { } accessor &&
6161
accessor.IsKind(SyntaxKind.SetAccessorDeclaration))
6262
{
@@ -72,9 +72,9 @@ private static bool IsReassignedWithCreated(AssignmentExpressionSyntax assignmen
7272
{
7373
switch (assignedSymbol)
7474
{
75-
case IPropertySymbol { ContainingType: { MetadataName: "SerialDisposable`1" }, MetadataName: "Disposable" }:
76-
case IPropertySymbol { ContainingType: { MetadataName: "SerialDisposable" }, MetadataName: "Disposable" }:
77-
case IPropertySymbol { ContainingType: { MetadataName: "SingleAssignmentDisposable" }, MetadataName: "Disposable" }:
75+
case IPropertySymbol { ContainingType.MetadataName: "SerialDisposable`1", MetadataName: "Disposable" }:
76+
case IPropertySymbol { ContainingType.MetadataName: "SerialDisposable", MetadataName: "Disposable" }:
77+
case IPropertySymbol { ContainingType.MetadataName: "SingleAssignmentDisposable", MetadataName: "Disposable" }:
7878
case IDiscardSymbol:
7979
return false;
8080
}
@@ -117,7 +117,7 @@ private static bool IsReassignedWithCreated(AssignmentExpressionSyntax assignmen
117117
{
118118
using var walker = VariableDeclaratorWalker.Borrow(memberDeclaration);
119119
return walker.VariableDeclarators.TrySingle(
120-
x => x is { Initializer: { Value: { } value } } &&
120+
x => x is { Initializer.Value: { } value } &&
121121
context.SemanticModel.TryGetSymbol(value, context.CancellationToken, out var symbol) &&
122122
SymbolComparer.Equal(symbol, assignedSymbol),
123123
out var match) &&

IDisposableAnalyzers/Analyzers/CreationAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ context.ContainingSymbol is { } &&
5151
{
5252
return context.Node switch
5353
{
54-
InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax { Expression: { } expression, Name: { Identifier: { ValueText: "Schedule" } } } }
54+
InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax { Expression: { } expression, Name.Identifier.ValueText: "Schedule" } }
5555
when context.SemanticModel.TryGetNamedType(expression, context.CancellationToken, out var type) &&
5656
type.IsAssignableTo(KnownSymbols.RxIScheduler, context.SemanticModel.Compilation)
5757
=> null,

IDisposableAnalyzers/Analyzers/DisposeCallAnalyzer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bool NotLeaveOpen()
7272
{
7373
return condition switch
7474
{
75-
PrefixUnaryExpressionSyntax { OperatorToken: { RawKind: (int)SyntaxKind.ExclamationToken }, Operand: { } operand }
75+
PrefixUnaryExpressionSyntax { OperatorToken.RawKind: (int)SyntaxKind.ExclamationToken, Operand: { } operand }
7676
when Field(operand)?.EndsWith("leaveOpen", StringComparison.OrdinalIgnoreCase) is true &&
7777
ifStatement.Statement.Contains(invocation)
7878
=> false,
@@ -180,13 +180,13 @@ declaration is VariableDeclaratorSyntax declarator &&
180180
bool DeclarationIsAssignment()
181181
{
182182
return localDeclarationStatement!.Parent == expressionStatement!.Parent &&
183-
declarator is { Initializer: { Value: { } value } } &&
183+
declarator is { Initializer.Value: { } value } &&
184184
Disposable.IsCreation(value, context.SemanticModel, context.CancellationToken);
185185
}
186186

187187
bool IsTrivialTryFinally()
188188
{
189-
return expressionStatement!.Parent is BlockSyntax { Statements: { Count: 1 }, Parent: FinallyClauseSyntax { Parent: TryStatementSyntax tryStatement } } &&
189+
return expressionStatement!.Parent is BlockSyntax { Statements.Count: 1, Parent: FinallyClauseSyntax { Parent: TryStatementSyntax tryStatement } } &&
190190
!tryStatement.Catches.Any();
191191
}
192192

IDisposableAnalyzers/Analyzers/DisposeMethodAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private static void Handle(SyntaxNodeAnalysisContext context)
3535
context.ContainingSymbol is IMethodSymbol { IsStatic: false, ReturnsVoid: true, Name: "Dispose" } method &&
3636
context.Node is MethodDeclarationSyntax methodDeclaration)
3737
{
38-
if (method is { DeclaredAccessibility: Accessibility.Public, Parameters: { Length: 0 } } &&
38+
if (method is { DeclaredAccessibility: Accessibility.Public, Parameters.Length: 0 } &&
3939
method.GetAttributes().Length == 0)
4040
{
4141
if (!method.ExplicitInterfaceImplementations.Any() &&
@@ -100,7 +100,7 @@ private static bool IsInterfaceImplementation(IMethodSymbol method)
100100
{
101101
foreach (var member in @interface.GetMembers())
102102
{
103-
if (member is IMethodSymbol { DeclaredAccessibility: Accessibility.Public, ReturnsVoid: true, Name: "Dispose", Parameters: { Length: 0 } })
103+
if (member is IMethodSymbol { DeclaredAccessibility: Accessibility.Public, ReturnsVoid: true, Name: "Dispose", Parameters.Length: 0 })
104104
{
105105
return true;
106106
}

IDisposableAnalyzers/Analyzers/FieldAndPropertyDeclarationAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static void HandleProperty(SyntaxNodeAnalysisContext context)
4141
{
4242
if (!context.IsExcludedFromAnalysis() &&
4343
context.ContainingSymbol is IPropertySymbol { IsStatic: false, IsIndexer: false } property &&
44-
context.Node is PropertyDeclarationSyntax { AccessorList: { Accessors: { } accessors } } declaration &&
44+
context.Node is PropertyDeclarationSyntax { AccessorList.Accessors: { } accessors } declaration &&
4545
accessors.FirstOrDefault() is { Body: null, ExpressionBody: null } &&
4646
Disposable.IsPotentiallyAssignableFrom(property.Type, context.Compilation))
4747
{

IDisposableAnalyzers/Analyzers/LocalDeclarationAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private static void Handle(SyntaxNodeAnalysisContext context)
4545
{
4646
foreach (var declarator in variables)
4747
{
48-
if (declarator is { Initializer: { Value: { } value } } &&
48+
if (declarator is { Initializer.Value: { } value } &&
4949
Disposable.IsCachedOrInjectedOnly(value, value, context.SemanticModel, context.CancellationToken))
5050
{
5151
context.ReportDiagnostic(Diagnostic.Create(Descriptors.IDISP007DoNotDisposeInjected, value.GetLocation()));

IDisposableAnalyzers/Analyzers/ReturnValueAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private static void HandleReturnValue(SyntaxNodeAnalysisContext context, Express
101101
}
102102
}
103103
}
104-
else if (returnValue is InvocationExpressionSyntax { ArgumentList: { Arguments: { } arguments } } invocation &&
104+
else if (returnValue is InvocationExpressionSyntax { ArgumentList.Arguments: { } arguments } invocation &&
105105
context.ContainingSymbol is { ContainingType: { } containingType })
106106
{
107107
foreach (var argument in arguments)
@@ -153,7 +153,7 @@ private static bool ShouldAwait(SyntaxNodeAnalysisContext context, ExpressionSyn
153153
{
154154
InvocationExpressionSyntax invocation
155155
=> !invocation.IsSymbol(KnownSymbols.Task.FromResult, context.SemanticModel, context.CancellationToken),
156-
MemberAccessExpressionSyntax { Name: { Identifier: { ValueText: "CompletedTask" } } } memberAccess
156+
MemberAccessExpressionSyntax { Name.Identifier.ValueText: "CompletedTask" } memberAccess
157157
=> !memberAccess.IsSymbol(KnownSymbols.Task.CompletedTask, context.SemanticModel, context.CancellationToken),
158158
_ => true,
159159
};

IDisposableAnalyzers/Analyzers/SuppressFinalizeAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override void Initialize(AnalysisContext context)
2222

2323
private static void Handle(SyntaxNodeAnalysisContext context)
2424
{
25-
if (context.Node is InvocationExpressionSyntax { ArgumentList: { Arguments: { Count: 1 } arguments } } invocation &&
25+
if (context.Node is InvocationExpressionSyntax { ArgumentList.Arguments: { Count: 1 } arguments } invocation &&
2626
invocation.IsSymbol(KnownSymbols.GC.SuppressFinalize, context.SemanticModel, context.CancellationToken) &&
2727
context.SemanticModel.TryGetNamedType(arguments[0].Expression, context.CancellationToken, out var type) &&
2828
type.IsSealed &&

IDisposableAnalyzers/Analyzers/UsingStatementAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ private static void Handle(SyntaxNodeAnalysisContext context)
2727
{
2828
switch (usingStatement)
2929
{
30-
case { Declaration: { Variables: { } variables } }:
30+
case { Declaration.Variables: { } variables }:
3131
foreach (var declarator in variables)
3232
{
33-
if (declarator is { Initializer: { Value: { } value } } &&
33+
if (declarator is { Initializer.Value: { } value } &&
3434
Disposable.IsCachedOrInjectedOnly(value, value, context.SemanticModel, context.CancellationToken))
3535
{
3636
context.ReportDiagnostic(Diagnostic.Create(Descriptors.IDISP007DoNotDisposeInjected, value.GetLocation()));

IDisposableAnalyzers/CodeFixes/AddBaseCallFix.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected override async Task RegisterCodeFixesAsync(DocumentEditorCodeFixContex
2727
{
2828
if (syntaxRoot?.FindNode(diagnostic.Location.SourceSpan) is MethodDeclarationSyntax { Body: { } body } disposeMethod)
2929
{
30-
if (disposeMethod is { ParameterList: { Parameters: { Count: 1 } parameters } } &&
30+
if (disposeMethod is { ParameterList.Parameters: { Count: 1 } parameters } &&
3131
parameters.TrySingle(out var parameter))
3232
{
3333
context.RegisterCodeFix(
@@ -47,7 +47,7 @@ protected override async Task RegisterCodeFixesAsync(DocumentEditorCodeFixContex
4747
"base.Dispose()",
4848
diagnostic);
4949
}
50-
else if (disposeMethod is { ParameterList: { Parameters: { Count: 0 } } })
50+
else if (disposeMethod is { ParameterList.Parameters.Count: 0 })
5151
{
5252
context.RegisterCodeFix(
5353
"base.Dispose()",

0 commit comments

Comments
 (0)