@@ -40,7 +40,7 @@ private static void HandleProperty(SyntaxNodeAnalysisContext context)
4040 if ( ! context . IsExcludedFromAnalysis ( ) &&
4141 context . ContainingSymbol is IPropertySymbol { IsStatic : false , IsIndexer : false } property &&
4242 context . Node is PropertyDeclarationSyntax { AccessorList : { Accessors : { } accessors } } declaration &&
43- accessors . First ( ) is { Body : null , ExpressionBody : null } &&
43+ accessors . FirstOrDefault ( ) is { Body : null , ExpressionBody : null } &&
4444 Disposable . IsPotentiallyAssignableFrom ( property . Type , context . Compilation ) )
4545 {
4646 HandleFieldOrProperty ( context , new FieldOrPropertyAndDeclaration ( property , declaration ) ) ;
@@ -74,41 +74,30 @@ private static void HandleFieldOrProperty(SyntaxNodeAnalysisContext context, Fie
7474
7575 private static bool IsMutableFromOutside ( FieldOrProperty fieldOrProperty )
7676 {
77- if ( fieldOrProperty . Symbol is IFieldSymbol field )
77+ return fieldOrProperty . Symbol switch
7878 {
79- if ( field . IsReadOnly )
80- {
81- return false ;
82- }
83-
84- return IsAccessible ( field . DeclaredAccessibility , field . ContainingType ) ;
85- }
86-
87- if ( fieldOrProperty . Symbol is IPropertySymbol property )
88- {
89- return IsAccessible ( property . DeclaredAccessibility , property . ContainingType ) &&
90- property . SetMethod is { } set &&
91- IsAccessible ( set . DeclaredAccessibility , property . ContainingType ) ;
92- }
93-
94- throw new InvalidOperationException ( "Should not get here." ) ;
79+ IFieldSymbol { IsReadOnly : true } => false ,
80+ IFieldSymbol field
81+ => IsAccessible ( field . DeclaredAccessibility , field . ContainingType ) ,
82+ IPropertySymbol property
83+ => IsAccessible ( property . DeclaredAccessibility , property . ContainingType ) &&
84+ property . SetMethod is { } set &&
85+ IsAccessible ( set . DeclaredAccessibility , property . ContainingType ) ,
86+ _ => throw new InvalidOperationException ( "Should not get here." ) ,
87+ } ;
9588
9689 static bool IsAccessible ( Accessibility accessibility , INamedTypeSymbol containingType )
9790 {
98- switch ( accessibility )
91+ return accessibility switch
9992 {
100- case Accessibility . Private :
101- return false ;
102- case Accessibility . Protected :
103- return ! containingType . IsSealed ;
104- case Accessibility . Internal :
105- case Accessibility . ProtectedOrInternal :
106- case Accessibility . ProtectedAndInternal :
107- case Accessibility . Public :
108- return true ;
109- default :
110- throw new ArgumentOutOfRangeException ( nameof ( accessibility ) , accessibility , "Unhandled accessibility" ) ;
111- }
93+ Accessibility . Private => false ,
94+ Accessibility . Protected => ! containingType . IsSealed ,
95+ Accessibility . Internal => true ,
96+ Accessibility . ProtectedOrInternal => true ,
97+ Accessibility . ProtectedAndInternal => true ,
98+ Accessibility . Public => true ,
99+ _ => throw new ArgumentOutOfRangeException ( nameof ( accessibility ) , accessibility , "Unhandled accessibility" )
100+ } ;
112101 }
113102 }
114103 }
0 commit comments