@@ -27,13 +27,11 @@ public override void Initialize(AnalysisContext context)
2727 private static void HandleField ( SyntaxNodeAnalysisContext context )
2828 {
2929 if ( ! context . IsExcludedFromAnalysis ( ) &&
30- context . ContainingSymbol is IFieldSymbol field &&
31- ! field . IsStatic &&
32- ! field . IsConst &&
33- FieldOrProperty . TryCreate ( field , out var fieldOrProperty ) &&
30+ context . ContainingSymbol is IFieldSymbol { IsStatic : false , IsConst : false } field &&
31+ context . Node is FieldDeclarationSyntax declaration &&
3432 Disposable . IsPotentiallyAssignableFrom ( field . Type , context . Compilation ) )
3533 {
36- HandleFieldOrProperty ( context , fieldOrProperty ) ;
34+ HandleFieldOrProperty ( context , new FieldOrPropertyAndDeclaration ( field , declaration ) ) ;
3735 }
3836 }
3937
@@ -51,45 +49,43 @@ private static void HandleProperty(SyntaxNodeAnalysisContext context)
5149 return ;
5250 }
5351
54- var propertyDeclaration = ( PropertyDeclarationSyntax ) context . Node ;
55- if ( propertyDeclaration . ExpressionBody != null )
52+ var declaration = ( PropertyDeclarationSyntax ) context . Node ;
53+ if ( declaration . ExpressionBody != null )
5654 {
5755 return ;
5856 }
5957
60- if ( propertyDeclaration . TryGetSetter ( out var setter ) &&
58+ if ( declaration . TryGetSetter ( out var setter ) &&
6159 setter . Body != null )
6260 {
6361 // Handle the backing field
6462 return ;
6563 }
6664
67- if ( FieldOrProperty . TryCreate ( property , out var fieldOrProperty ) &&
68- Disposable . IsPotentiallyAssignableFrom ( property . Type , context . Compilation ) )
65+ if ( Disposable . IsPotentiallyAssignableFrom ( property . Type , context . Compilation ) )
6966 {
70- HandleFieldOrProperty ( context , fieldOrProperty ) ;
67+ HandleFieldOrProperty ( context , new FieldOrPropertyAndDeclaration ( property , declaration ) ) ;
7168 }
7269 }
7370
74- private static void HandleFieldOrProperty ( SyntaxNodeAnalysisContext context , FieldOrProperty fieldOrProperty )
71+ private static void HandleFieldOrProperty ( SyntaxNodeAnalysisContext context , FieldOrPropertyAndDeclaration member )
7572 {
76- using var assignedValues = AssignedValueWalker . Borrow ( fieldOrProperty . Symbol , context . SemanticModel , context . CancellationToken ) ;
73+ using var assignedValues = AssignedValueWalker . Borrow ( member . FieldOrProperty . Symbol , context . SemanticModel , context . CancellationToken ) ;
7774 using var recursive = RecursiveValues . Borrow ( assignedValues , context . SemanticModel , context . CancellationToken ) ;
7875 if ( Disposable . IsAnyCreation ( recursive , context . SemanticModel , context . CancellationToken ) . IsEither ( Result . Yes , Result . AssumeYes ) )
7976 {
8077 if ( Disposable . IsAnyCachedOrInjected ( recursive , context . SemanticModel , context . CancellationToken ) . IsEither ( Result . Yes , Result . AssumeYes ) ||
81- IsMutableFromOutside ( fieldOrProperty ) )
78+ IsMutableFromOutside ( member . FieldOrProperty ) )
8279 {
8380 context . ReportDiagnostic ( Diagnostic . Create ( Descriptors . IDISP008DoNotMixInjectedAndCreatedForMember , context . Node . GetLocation ( ) ) ) ;
8481 }
85- else if ( context . Node . TryFirstAncestorOrSelf < TypeDeclarationSyntax > ( out var typeDeclaration ) &&
86- DisposableMember . IsDisposed ( fieldOrProperty , typeDeclaration , context . SemanticModel , context . CancellationToken ) . IsEither ( Result . No , Result . AssumeNo ) &&
87- ! TestFixture . IsAssignedInInitializeAndDisposedInCleanup ( fieldOrProperty , typeDeclaration , context . SemanticModel , context . CancellationToken ) )
82+ else if ( DisposableMember . IsDisposed ( member , context . SemanticModel , context . CancellationToken ) . IsEither ( Result . No , Result . AssumeNo ) &&
83+ ! TestFixture . IsAssignedInInitializeAndDisposedInCleanup ( member , context . SemanticModel , context . CancellationToken ) )
8884 {
8985 context . ReportDiagnostic ( Diagnostic . Create ( Descriptors . IDISP002DisposeMember , context . Node . GetLocation ( ) ) ) ;
9086
91- if ( ! DisposeMethod . TryFindFirst ( fieldOrProperty . ContainingType , context . Compilation , Search . TopLevel , out _ ) &&
92- ! TestFixture . IsAssignedInInitialize ( fieldOrProperty , typeDeclaration , context . SemanticModel , context . CancellationToken , out _ , out _ ) )
87+ if ( ! DisposeMethod . TryFindFirst ( member . FieldOrProperty . ContainingType , context . Compilation , Search . TopLevel , out _ ) &&
88+ ! TestFixture . IsAssignedInInitialize ( member , context . SemanticModel , context . CancellationToken , out _ , out _ ) )
9389 {
9490 context . ReportDiagnostic ( Diagnostic . Create ( Descriptors . IDISP006ImplementIDisposable , context . Node . GetLocation ( ) ) ) ;
9591 }
0 commit comments