CSharp examples for System.Reflection:Assembly
Get All Impl Of Generic Interface
using System.Threading.Tasks; using System.Text; using System.Reflection; using System.Linq; using System.Collections.Generic; using System;//from w w w .j a v a 2s.c om public class Main{ public static List<Type> GetAllImplOfGenericInterface(this Assembly assembly, Type genericType, List<Type> ignoreTypes) { List<Type> types = assembly.GetTypes() .Where(type => type.GetInterfaces() .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IQueryHandler<,>))).ToList(); foreach (var ignoreType in ignoreTypes) types.Remove(ignoreType); return types; } public static List<Type> GetAllImplOfGenericInterface(this Assembly assembly, Type genericType) { List<Type> types = assembly.GetTypes() .Where(type => type.GetInterfaces() .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IQueryHandler<,>))).ToList(); return types; } }