@@ -9,36 +9,25 @@ internal static class TypeExtensions
99 {
1010 public static bool IsVirtualOrAbstract ( this MemberInfo member )
1111 {
12- if ( member is MethodInfo method )
13- {
14- return method . IsVirtual || method . IsAbstract ;
15- }
16-
17- if ( member is PropertyInfo property )
18- {
19- MethodInfo ? accessor = property . GetFirstMethod ( ) ;
20- return accessor ? . IsVirtual is true || accessor ? . IsAbstract is true ;
21- }
22-
23- if ( member is EventInfo eventInfo )
12+ return member switch
2413 {
25- MethodInfo ? accessor = eventInfo . GetFirstMethod ( ) ;
26- return accessor ? . IsVirtual is true || accessor ? . IsAbstract is true ;
27- }
28-
29- return false ;
14+ MethodInfo method => method . IsVirtualOrAbstract ( ) ,
15+ PropertyInfo property => property . GetFirstMethod ( ) . IsVirtualOrAbstract ( ) ,
16+ EventInfo eventInfo => eventInfo . GetFirstMethod ( ) . IsVirtualOrAbstract ( ) ,
17+ _ => false ,
18+ } ;
3019 }
3120
32- public static bool IsVirtualOrAbstract ( this MethodInfo method )
33- => method . IsVirtual || method . IsAbstract ;
21+ public static bool IsVirtualOrAbstract ( this MethodInfo ? method )
22+ => method is { IsFinal : false } and ( { IsVirtual : true } or { IsAbstract : true } ) ;
3423
3524 public static bool IsVirtual ( this MemberInfo member )
3625 {
3726 return member switch
3827 {
39- MethodInfo method => method . IsVirtual ,
40- PropertyInfo property => property . GetFirstMethod ( ) ? . IsVirtual is true ,
41- EventInfo eventInfo => eventInfo . GetFirstMethod ( ) ? . IsVirtual is true ,
28+ MethodInfo method => method is { IsVirtual : true , IsFinal : false , IsAbstract : false } ,
29+ PropertyInfo property => property . GetFirstMethod ( ) is { IsVirtual : true , IsFinal : false , IsAbstract : false } ,
30+ EventInfo eventInfo => eventInfo . GetFirstMethod ( ) is { IsVirtual : true , IsFinal : false , IsAbstract : false } ,
4231 _ => false ,
4332 } ;
4433 }
0 commit comments