99
1010internal static partial class Disposable
1111{
12- internal static bool IsPotentiallyAssignableFrom ( ExpressionSyntax candidate , SemanticModel semanticModel , CancellationToken cancellationToken )
12+ internal static bool IsPotentiallyAssignableFrom ( ExpressionSyntax candidate , SemanticModel semanticModel , CancellationToken cancellationToken ) => candidate switch
1313 {
14- return candidate switch
15- {
16- { IsMissing : true } => false ,
17- LiteralExpressionSyntax _ => false ,
18- ObjectCreationExpressionSyntax objectCreation
19- => semanticModel . TryGetType ( objectCreation , cancellationToken , out var type ) &&
20- IsAssignableFrom ( type , semanticModel . Compilation ) ,
21- _ => semanticModel . TryGetType ( candidate , cancellationToken , out var type ) &&
22- IsPotentiallyAssignableFrom ( type , semanticModel . Compilation ) ,
23- } ;
24- }
14+ { IsMissing : true } => false ,
15+ LiteralExpressionSyntax _ => false ,
16+ ObjectCreationExpressionSyntax objectCreation
17+ => semanticModel . TryGetType ( objectCreation , cancellationToken , out var type ) &&
18+ IsAssignableFrom ( type , semanticModel . Compilation ) ,
19+ _ => semanticModel . TryGetType ( candidate , cancellationToken , out var type ) &&
20+ IsPotentiallyAssignableFrom ( type , semanticModel . Compilation ) ,
21+ } ;
2522
2623 internal static bool IsPotentiallyAssignableFrom ( ITypeSymbol type , Compilation compilation )
2724 {
@@ -45,18 +42,16 @@ internal static bool IsPotentiallyAssignableFrom(ITypeSymbol type, Compilation c
4542 return true ;
4643 }
4744
48- internal static bool IsAssignableFrom ( ITypeSymbol type , Compilation compilation )
45+ internal static bool IsAssignableFrom ( ITypeSymbol type , Compilation compilation ) => type switch
4946 {
50- return type switch
51- {
52- null => false ,
53- //// https://blogs.msdn.microsoft.com/pfxteam/2012/03/25/do-i-need-to-dispose-of-tasks/
54- { ContainingNamespace : { MetadataName : "Tasks" , ContainingNamespace : { MetadataName : "Threading" , ContainingNamespace . MetadataName : "System" } } , MetadataName : "Task" } => false ,
55- INamedTypeSymbol { ContainingNamespace : { MetadataName : "Tasks" , ContainingNamespace : { MetadataName : "Threading" , ContainingNamespace . MetadataName : "System" } } , MetadataName : "Task`1" , TypeArguments : { Length : 1 } arguments }
56- => IsAssignableFrom ( arguments [ 0 ] , compilation ) ,
57- _ => type . IsAssignableTo ( KnownSymbols . IDisposable , compilation ) ,
58- } ;
59- }
47+ null => false ,
48+ //// https://blogs.msdn.microsoft.com/pfxteam/2012/03/25/do-i-need-to-dispose-of-tasks/
49+ { ContainingNamespace : { MetadataName : "Tasks" , ContainingNamespace : { MetadataName : "Threading" , ContainingNamespace . MetadataName : "System" } } , MetadataName : "Task" } => false ,
50+ INamedTypeSymbol { ContainingNamespace : { MetadataName : "Tasks" , ContainingNamespace : { MetadataName : "Threading" , ContainingNamespace . MetadataName : "System" } } , MetadataName : "Task`1" , TypeArguments : { Length : 1 } arguments }
51+ => IsAssignableFrom ( arguments [ 0 ] , compilation ) ,
52+ { IsRefLikeType : true } => DisposeMethod . IsAccessibleOn ( type , compilation ) ,
53+ _ => type . IsAssignableTo ( KnownSymbols . IDisposable , compilation ) ,
54+ } ;
6055
6156 internal static bool IsNop ( ExpressionSyntax candidate , SemanticModel semanticModel , CancellationToken cancellationToken )
6257 {
0 commit comments