GetAssemblies() public static method

Get all assemblies referenced by specified asmFilename(self included) recursively.
public static GetAssemblies ( string asmFilename ) : System.Reflection.Assembly[]
asmFilename string
return System.Reflection.Assembly[]
示例#1
0
        /// <summary>
        /// Get all derived non-abstract types of specified base type from all loaded assemblies.
        /// </summary>
        /// <param name="baseType"></param>
        /// <param name="addtionalFilter">addtional filter.</param>
        /// <returns></returns>
        public static List <Type> GetAllDerivedTypes(this Type baseType, Func <Type, bool> addtionalFilter = null)
        {
            //if (addtionalFilter == null) { addtionalFilter = x => !x.IsAbstract; }
            var result = new List <Type>();

            Assembly[] assemblies = AssemblyHelper.GetAssemblies(AppDomain.CurrentDomain.BaseDirectory);
            foreach (Assembly asm in assemblies)
            {
                try
                {
                    var list = from item in asm.GetTypes()
                               where baseType.IsAssignableFrom(item) &&
                               (addtionalFilter == null || (addtionalFilter(item)))
                               orderby item.FullName
                               select item;
                    foreach (Type item in list.Distinct())
                    {
                        result.Add(item);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Assembly Helper: {0}", ex));
                }
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Get all derived non-abstract types of specified base type from all loaded assemblies.
        /// </summary>
        /// <param name="baseType"></param>
        /// <param name="addtionalFilter">addtional filter.</param>
        /// <returns></returns>
        public static List <Type> GetAllDerivedTypes(this Type baseType, Func <Type, bool> addtionalFilter = null)
        {
            //if (addtionalFilter == null) { addtionalFilter = x => !x.IsAbstract; }
            var result = new List <Type>();

            Assembly[] assemblies = AssemblyHelper.GetAssemblies(Application.ExecutablePath);
            foreach (var asm in assemblies)
            {
                var list = from item in asm.GetTypes()
                           where baseType.IsAssignableFrom(item) &&
                           (addtionalFilter == null || (addtionalFilter(item)))
                           select item;
                foreach (var item in list.Distinct())
                {
                    result.Add(item);
                }
            }

            return(result);
        }