@@ -15,17 +15,19 @@ public class Detector
1515 // Aspects must be listed in the order of detection, from the biggest (the most generic) to the
1616 // smallest (the least generic) aspects.
1717 public readonly static List < Type > KnownTopLevelAspects = new ( ) {
18- typeof ( ApplicationPackage ) ,
18+ typeof ( PackageAPK ) ,
19+ typeof ( PackageAAB ) ,
20+ typeof ( PackageBase ) ,
1921 typeof ( AssemblyStore ) ,
2022 typeof ( ApplicationAssembly ) ,
2123 typeof ( NativeAotSharedLibrary ) ,
22- typeof ( LibXamarinApp ) ,
24+ typeof ( XamarinAppSharedLibrary ) ,
2325 typeof ( SharedLibrary ) ,
2426 } ;
2527
2628 readonly static List < Type > KnownSharedLibraryAspects = new ( ) {
2729 typeof ( NativeAotSharedLibrary ) ,
28- typeof ( LibXamarinApp ) ,
30+ typeof ( XamarinAppSharedLibrary ) ,
2931 typeof ( SharedLibrary ) ,
3032 } ;
3133
@@ -49,44 +51,53 @@ public class Detector
4951 public static SharedLibrary ? FindSharedLibraryAspect ( Stream stream , string ? description = null )
5052 {
5153 Log . Debug ( $ "Looking for shared library aspect ('{ description } ')") ;
52- // TODO: implement
54+ return ( SharedLibrary ? ) TryFindAspect ( KnownSharedLibraryAspects , stream , description ) ;
55+ }
56+
57+ static IAspect ? TryFindTopLevelAspect ( Stream stream , string ? description ) => TryFindAspect ( KnownTopLevelAspects , stream , description ) ;
58+
59+ static IAspect ? TryFindAspect ( List < Type > aspectTypes , Stream stream , string ? description )
60+ {
61+ foreach ( Type aspectType in aspectTypes ) {
62+ IAspect ? aspect = TryProbeAndLoadAspect ( aspectType , stream , description ) ;
63+ if ( aspect != null ) {
64+ return aspect ;
65+ }
66+ }
67+
5368 return null ;
5469 }
5570
56- static IAspect ? TryFindTopLevelAspect ( Stream stream , string ? description )
71+ static IAspect ? TryProbeAndLoadAspect ( Type aspect , Stream stream , string ? description )
5772 {
58- var flags = BindingFlags . InvokeMethod | BindingFlags . Public | BindingFlags . Static ;
73+ const BindingFlags flags = BindingFlags . InvokeMethod | BindingFlags . Public | BindingFlags . Static | BindingFlags . FlattenHierarchy ;
5974
60- foreach ( Type aspect in KnownTopLevelAspects ) {
61- LogBanner ( $ "Probing aspect: { aspect } ") ;
75+ LogBanner ( $ "Probing aspect: { aspect } ") ;
76+ object ? result = aspect . InvokeMember (
77+ "ProbeAspect" , flags , null , null , new object ? [ ] { stream , description }
78+ ) ;
6279
63- object ? result = aspect . InvokeMember (
64- "ProbeAspect" , flags , null , null , new object ? [ ] { stream , description }
65- ) ;
80+ var state = result as IAspectState ;
81+ if ( state == null || ! state . Success ) {
82+ return null ;
83+ }
6684
67- var state = result as IAspectState ;
68- if ( state == null || ! state . Success ) {
69- continue ;
70- }
85+ LogBanner ( $ "Loading aspect: { aspect } " ) ;
86+ result = aspect . InvokeMember (
87+ "LoadAspect" , flags , null , null , new object ? [ ] { stream , state , description }
88+ ) ;
7189
72- LogBanner ( $ "Loading aspect: { aspect } ") ;
73- result = aspect . InvokeMember (
74- "LoadAspect" , flags , null , null , new object ? [ ] { stream , state , description }
75- ) ;
76- if ( result != null ) {
77- return ( IAspect ) result ;
78- }
90+ if ( result != null ) {
91+ return ( IAspect ) result ;
7992 }
8093
8194 return null ;
8295
8396 void LogBanner ( string what )
8497 {
8598 Log . Debug ( ) ;
86- Log . Debug ( "##########" ) ;
87- Log . Debug ( what ) ;
99+ Log . Debug ( $ "# { what } ") ;
88100 Log . Debug ( ) ;
89101 }
90102 }
91-
92103}
0 commit comments