@@ -33,20 +33,23 @@ static bool IsMatch(IMethodSymbol candidate)
3333 }
3434 }
3535
36- internal static bool TryFindVirtual ( ITypeSymbol type , Compilation compilation , Search search , [ NotNullWhen ( true ) ] out IMethodSymbol ? disposeMethod )
36+ internal static IMethodSymbol ? FindVirtual ( ITypeSymbol type , Compilation compilation , Search search )
3737 {
38- disposeMethod = null ;
3938 if ( ! type . IsAssignableTo ( KnownSymbol . IDisposable , compilation ) )
4039 {
41- return false ;
40+ return null ;
4241 }
4342
4443 if ( search == Search . TopLevel )
4544 {
46- return type . TryFindFirstMethod ( "Dispose" , x => IsMatch ( x ) , out disposeMethod ) ;
45+ return type . TryFindFirstMethod ( "Dispose" , x => IsMatch ( x ) , out var topLevel )
46+ ? topLevel
47+ : null ;
4748 }
4849
49- return type . TryFindFirstMethodRecursive ( "Dispose" , x => IsMatch ( x ) , out disposeMethod ) ;
50+ return type . TryFindFirstMethodRecursive ( "Dispose" , x => IsMatch ( x ) , out var recursive )
51+ ? recursive
52+ : null ;
5053
5154 static bool IsMatch ( IMethodSymbol candidate )
5255 {
@@ -55,31 +58,25 @@ static bool IsMatch(IMethodSymbol candidate)
5558 }
5659 }
5760
58- internal static bool TryFindFirst ( ITypeSymbol type , Compilation compilation , Search search , [ NotNullWhen ( true ) ] out IMethodSymbol ? disposeMethod )
61+ internal static IMethodSymbol ? FindFirst ( ITypeSymbol type , Compilation compilation , Search search )
5962 {
6063 if ( search == Search . TopLevel )
6164 {
62- if ( Find ( type , compilation , search ) is { } match )
63- {
64- disposeMethod = match ;
65- return true ;
66- }
67-
68- return TryFindVirtual ( type , compilation , search , out disposeMethod ) ;
65+ return Find ( type , compilation , Search . TopLevel ) ??
66+ FindVirtual ( type , compilation , Search . TopLevel ) ;
6967 }
7068
7169 while ( type . IsAssignableTo ( KnownSymbol . IDisposable , compilation ) )
7270 {
73- if ( TryFindFirst ( type , compilation , Search . TopLevel , out disposeMethod ) )
71+ if ( FindFirst ( type , compilation , Search . TopLevel ) is { } disposeMethod )
7472 {
75- return true ;
73+ return disposeMethod ;
7674 }
7775
7876 type = type . BaseType ;
7977 }
8078
81- disposeMethod = null ;
82- return false ;
79+ return null ;
8380 }
8481
8582 internal static bool IsAccessibleOn ( ITypeSymbol type , Compilation compilation )
0 commit comments