File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed
Microsoft.Azure.Functions.Worker.Extensions.OpenApi/Extensions
Microsoft.Azure.WebJobs.Extensions.OpenApi.Core Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Linq ;
44using System . Reflection ;
Original file line number Diff line number Diff line change 1- using System ;
1+ using System ;
22using System . Linq ;
33using System . Reflection ;
44
@@ -10,15 +10,23 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
1010 public static class AssemblyExtensions
1111 {
1212 /// <summary>
13- /// Loads the <see cref="Assembly"/>'s <see cref="Type"/>s that can be loaded ignoring others.
13+ /// Loads the <see cref="Assembly"/>'s <see cref="Type"/>s that can be loaded ignoring others (includes referenced assemblies) .
1414 /// </summary>
1515 /// <param name="assembly"><see cref="Assembly"/> instance.</param>
1616 /// <returns>Returns the list of <see cref="Type"/>s that can be loaded.</returns>
1717 public static Type [ ] GetLoadableTypes ( this Assembly assembly )
1818 {
1919 try
2020 {
21- return assembly . GetTypes ( ) ;
21+ return assembly . GetTypes ( )
22+ . Union ( assembly
23+ . GetReferencedAssemblies ( )
24+ . Where ( x =>
25+ ! x . FullName . StartsWith ( "Microsoft.Azure.WebJobs.Extensions.OpenApi" ) &&
26+ ! x . FullName . StartsWith ( "Microsoft.Azure.Functions.Worker.Extensions.OpenApi" ) )
27+ . SelectMany ( x => Assembly . Load ( x ) . GetTypes ( ) ) )
28+ . Distinct ( )
29+ . ToArray ( ) ;
2230 }
2331 catch ( ReflectionTypeLoadException exception )
2432 {
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ public static VisitorCollection CreateInstance()
4949 var collection = new VisitorCollection ( ) ;
5050 collection . Visitors = typeof ( IVisitor ) . Assembly
5151 . GetLoadableTypes ( )
52- . Where ( p => p . Name . EndsWith ( "Visitor" ) && p . IsClass && ! p . IsAbstract )
52+ . Where ( p => p . HasInterface < IVisitor > ( ) && p . IsClass && ! p . IsAbstract )
5353 . Select ( p => ( IVisitor ) Activator . CreateInstance ( p , collection ) ) . ToList ( ) ; // NOTE: there is no direct enforcement on the constructor arguments of the visitors
5454 return collection ;
5555 }
You can’t perform that action at this time.
0 commit comments