Get Assembly Implementations - CSharp System.Reflection

CSharp examples for System.Reflection:Assembly

Description

Get Assembly Implementations

Demo Code


using System.Reflection;
using System.Threading.Tasks;
using System.Linq;
using System.Collections.Generic;
using System;//from   w w w .ja va  2s . c o m

public class Main{
        public static IEnumerable<Type> GetImplementations<T>(this IEnumerable<Assembly> assemblies, Func<Assembly, bool> predicate)
        {
            List<Type> implementations = new List<Type>();

            foreach (Assembly assembly in assemblies)
                foreach (Type type in assembly.GetTypes())
                    if (typeof(T).GetTypeInfo().IsAssignableFrom(type) && type.GetTypeInfo().IsClass)
                        implementations.Add(type);

            return implementations;
        }
        public static IEnumerable<Type> GetImplementations<T>(this IEnumerable<Assembly> assemblies)
        {
            return assemblies.GetImplementations<T>(null);
        }
}

Related Tutorials