2020-12-25 20:17:17 +00:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Reflection ;
// The System.Reflection namespace is not used here because of the likelihood that another library will use identical functions. This can cause conflicts.
2021-01-29 15:16:45 +00:00
namespace Elsa
2020-12-25 20:17:17 +00:00
{
public static class AssemblyExtensions
{
public static IEnumerable < Type > GetAllWithInterface ( this Assembly assembly , Type @interface ) = > assembly . GetTypes ( ) . Where ( t = > t . IsClass & & t . IsAbstract = = false & & t . GetInterfaces ( ) . Contains ( @interface ) ) ;
2021-03-17 12:07:14 +00:00
public static IEnumerable < Type > GetAllWithBaseClass ( this Assembly assembly , Type baseClass ) = > assembly . GetTypes ( ) . Where ( baseClass . IsAssignableFrom ) ;
2021-06-18 13:22:57 +00:00
//public static IEnumerable<Type> GetAllWithAttribute(this Assembly assembly, Type attribute) => assembly.GetTypes().Where(t => t.GetCustomAttributes(typeof(attribute), true).Length > 0);
2020-12-25 20:17:17 +00:00
public static IEnumerable < Type > GetAllWithInterface < TType > ( this Assembly assembly ) = > assembly . GetAllWithInterface ( typeof ( TType ) ) ;
2021-03-17 12:07:14 +00:00
public static IEnumerable < Type > GetAllWithBaseClass < TType > ( this Assembly assembly ) = > assembly . GetAllWithBaseClass ( typeof ( TType ) ) ;
2021-06-18 13:22:57 +00:00
//public static IEnumerable<Type> GetAllWithAttribute<TType>(this Assembly assembly) => assembly.GetAllWithAttribute(typeof(TType));
2020-12-25 20:17:17 +00:00
}
}