using System; using System.Linq; using System.Reflection; namespace Sodao.FastSocket.SocketBase.Utils { /// /// 反射帮助类。 /// public static class ReflectionHelper { /// /// 获取实现了指定类口类型的基类实例。 /// /// 接口类型 /// 指定的程序集 /// /// assembly is null static public T[] GetImplementObjects(Assembly assembly) { if (assembly == null) throw new ArgumentNullException("assembly"); return assembly.GetExportedTypes().Where(c => { if (c.IsClass && !c.IsAbstract) { var interfaces = c.GetInterfaces(); if (interfaces != null) return interfaces.Contains(typeof(T)); } return false; }).Select(c => (T)c.GetConstructor(new Type[0]).Invoke(new object[0])).ToArray(); } } }