/// <summary>在指定程序集中查找指定基类的子类</summary> /// <param name="asm">指定程序集</param> /// <param name="baseType">基类或接口,为空时返回所有类型</param> /// <returns></returns> public virtual IEnumerable <Type> GetSubclasses(Assembly asm, Type baseType) { //if (asm == null) throw new ArgumentNullException(nameof(asm)); //if (baseType == null) throw new ArgumentNullException(nameof(baseType)); //foreach (var item in asm.GetTypes()) //{ // if (baseType != item && baseType.IsAssignableFrom(item)) // yield return item; //} return(AssemblyX.Create(asm).FindPlugins(baseType)); }
/// <summary>在所有程序集中查找指定基类或接口的子类实现</summary> /// <param name="baseType">基类或接口</param> /// <param name="isLoadAssembly">是否加载为加载程序集</param> /// <returns></returns> public virtual IEnumerable <Type> GetAllSubclasses(Type baseType, Boolean isLoadAssembly) { //// 不支持isLoadAssembly //foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) //{ // foreach (var type in GetSubclasses(asm, baseType)) // { // yield return type; // } //} return(AssemblyX.FindAllPlugins(baseType, isLoadAssembly)); }
/// <summary>根据名称获取类型</summary> /// <param name="typeName">类型名</param> /// <param name="isLoadAssembly">是否从未加载程序集中获取类型。使用仅反射的方法检查目标类型,如果存在,则进行常规加载</param> /// <returns></returns> public virtual Type GetType(String typeName, Boolean isLoadAssembly) => AssemblyX.GetType(typeName, isLoadAssembly);