44using System . Linq ;
55using System . Reflection ;
66using System . Text . RegularExpressions ;
7- using Microsoft . DotNet . PlatformAbstractions ;
8- using Microsoft . Extensions . DependencyModel ;
97using Shuttle . Core . Contract ;
108using Shuttle . Core . Logging ;
9+ #if ( NETCOREAPP2_0 || NETSTANDARD2_0 )
10+ using Microsoft . DotNet . PlatformAbstractions ;
11+ using Microsoft . Extensions . DependencyModel ;
12+ #endif
1113
1214namespace Shuttle . Core . Reflection
1315{
@@ -37,7 +39,7 @@ public string AssemblyPath(Assembly assembly)
3739
3840 public Assembly GetAssembly ( string assemblyPath )
3941 {
40- var result = RuntimeAssemblies ( )
42+ var result = GetRuntimeAssemblies ( )
4143 . FirstOrDefault ( assembly => AssemblyPath ( assembly )
4244 . Equals ( assemblyPath , StringComparison . InvariantCultureIgnoreCase ) ) ;
4345
@@ -104,7 +106,7 @@ public Assembly FindAssemblyNamed(string name)
104106 hasFileExtension = true ;
105107 }
106108
107- var result = RuntimeAssemblies ( )
109+ var result = GetRuntimeAssemblies ( )
108110 . FirstOrDefault ( assembly => assembly . GetName ( )
109111 . Name . Equals ( assemblyName , StringComparison . InvariantCultureIgnoreCase ) ) ;
110112
@@ -188,7 +190,7 @@ private IEnumerable<Assembly> GetMatchingAssemblies(Regex expression, string fol
188190
189191 public IEnumerable < Assembly > GetMatchingAssemblies ( string regex )
190192 {
191- var assemblies = new List < Assembly > ( RuntimeAssemblies ( ) ) ;
193+ var assemblies = new List < Assembly > ( GetRuntimeAssemblies ( ) ) ;
192194
193195 foreach (
194196 var assembly in
@@ -215,30 +217,34 @@ var assembly in
215217 return assemblies ;
216218 }
217219
218- public IEnumerable < Assembly > RuntimeAssemblies ( )
220+ public IEnumerable < Assembly > GetRuntimeAssemblies ( )
219221 {
220- var result = new List < Assembly > ( ) ;
222+ #if ( ! NETCOREAPP2_0 && ! NETSTANDARD2_0 )
223+ return AppDomain . CurrentDomain . GetAssemblies ( ) ;
224+ #else
225+ var result = new List < Assembly > ( ) ;
221226
222227 foreach ( var runtimeAssemblyName in DependencyContext . Default . GetRuntimeAssemblyNames ( RuntimeEnvironment . GetRuntimeIdentifier ( ) ) )
223228 {
224229 result . Add ( Assembly . Load ( runtimeAssemblyName ) ) ;
225230 }
226231
227232 return result ;
228- }
233+ #endif
234+ }
229235
230- public IEnumerable < Type > GetTypes < T > ( )
236+ public IEnumerable < Type > GetTypesAssignableTo < T > ( )
231237 {
232- return GetTypes ( typeof ( T ) ) ;
238+ return GetTypesAssignableTo ( typeof ( T ) ) ;
233239 }
234240
235- public IEnumerable < Type > GetTypes ( Type type )
241+ public IEnumerable < Type > GetTypesAssignableTo ( Type type )
236242 {
237243 var result = new List < Type > ( ) ;
238244
239245 foreach ( var assembly in GetAssemblies ( ) )
240246 {
241- GetTypes ( type , assembly )
247+ GetTypesAssignableTo ( type , assembly )
242248 . Where ( candidate => result . Find ( existing => existing == candidate ) == null )
243249 . ToList ( )
244250 . ForEach ( add => result . Add ( add ) ) ;
@@ -247,20 +253,20 @@ public IEnumerable<Type> GetTypes(Type type)
247253 return result ;
248254 }
249255
250- public IEnumerable < Type > GetTypes < T > ( Assembly assembly )
256+ public IEnumerable < Type > GetTypesAssignableTo < T > ( Assembly assembly )
251257 {
252- return GetTypes ( typeof ( T ) , assembly ) ;
258+ return GetTypesAssignableTo ( typeof ( T ) , assembly ) ;
253259 }
254260
255- public IEnumerable < Type > GetTypes ( Type type , Assembly assembly )
261+ public IEnumerable < Type > GetTypesAssignableTo ( Type type , Assembly assembly )
256262 {
257263 Guard . AgainstNull ( type , nameof ( type ) ) ;
258264 Guard . AgainstNull ( assembly , nameof ( assembly ) ) ;
259265
260- return GetTypes ( assembly ) . Where ( candidate => candidate . IsAssignableTo ( type ) && candidate != type ) . ToList ( ) ;
266+ return GetTypesAssignableTo ( assembly ) . Where ( candidate => candidate . IsAssignableTo ( type ) && ! ( candidate . IsInterface && candidate == type ) ) . ToList ( ) ;
261267 }
262268
263- public IEnumerable < Type > GetTypes ( Assembly assembly )
269+ public IEnumerable < Type > GetTypesAssignableTo ( Assembly assembly )
264270 {
265271 Type [ ] types ;
266272
0 commit comments