Example #1
0
 private static void LoadDerivedTypeInAllFolder(Type baseType, IList <Type> derivedTypeList, string folderPath, TypeLoadConfig config)
 {
     ReflectionHelper.LoadDerivedTypeInOneFolder(baseType, derivedTypeList, folderPath, config);
     string[] folders = Directory.GetDirectories(folderPath);
     if (folders != null)
     {
         foreach (string nextFolder in folders)
         {
             ReflectionHelper.LoadDerivedTypeInAllFolder(baseType, derivedTypeList, nextFolder, config);
         }
     }
 }
Example #2
0
        /// <summary>
        /// LoadDerivedType 加载directorySearched目录下所有程序集中的所有派生自baseType的类型
        /// </summary>
        /// <typeparam name="baseType">基类(或接口)类型</typeparam>
        /// <param name="directorySearched">搜索的目录</param>
        /// <param name="searchChildFolder">是否搜索子目录中的程序集</param>
        /// <param name="config">高级配置,可以传入null采用默认配置</param>
        /// <returns>所有从BaseType派生的类型列表</returns>
        public static IList <Type> LoadDerivedType(Type baseType, string directorySearched, bool searchChildFolder, TypeLoadConfig config)
        {
            if (config == null)
            {
                config = new TypeLoadConfig();
            }

            IList <Type> derivedTypeList = new List <Type>();

            if (searchChildFolder)
            {
                ReflectionHelper.LoadDerivedTypeInAllFolder(baseType, derivedTypeList, directorySearched, config);
            }
            else
            {
                ReflectionHelper.LoadDerivedTypeInOneFolder(baseType, derivedTypeList, directorySearched, config);
            }

            return(derivedTypeList);
        }