查找当前项目所有程序集的方法System.AppDomain.CurrentDomain.GetAssemblies();
List<Type> TypeItemList = new List<Type>(); //var ResultTypeList = Assembly.GetEntryAssembly(); //if (ResultTypeList == null) //{ // ResultTypeList = Assembly.GetCallingAssembly(); // var ItemList = ResultTypeList.GetReferencedAssemblies().Where(p => p.GetType() == typeof(BaseService)); //} Assembly[] AssbyCustmList = System.AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assItem in AssbyCustmList) { TypeItemList.AddRange(assItem.GetTypes().Where(x => x.BaseType == typeof(BaseService)).ToList()); } //IEnumerable<Type> TypeItemList = CurType.Assembly.GetExportedTypes().Where(x => x.BaseType == typeof(BaseService)).ToList(); //IEnumerable<Type> TypeItemList = ResultTypeList.GetTypes().Where(x => x.BaseType == typeof(BaseService)).ToList(); BaseService TarService = null; foreach (Type typeitem in TypeItemList) { if (_Reporttory.Count(p => p.GetType() == typeitem) == 0) { TarService = (Activator.CreateInstance(typeitem) as BaseService); } else { TarService = _Reporttory.First(p => p.GetType() == typeitem); } TarService.Start(); } static void ShowAssemblyDetail(Assembly assembly, string name = "") { Console.WriteLine("============ \n"); Console.WriteLine("FullName:" + assembly.FullName); Console.WriteLine("CodeBase:" + assembly.CodeBase); Console.WriteLine("EscapedCodeBase:" + assembly.EscapedCodeBase); Console.WriteLine("GlobalAssemblyCache:" + assembly.GlobalAssemblyCache); Console.WriteLine("HostContext:" + assembly.HostContext); Console.WriteLine("ImageRuntimeVersion:" + assembly.ImageRuntimeVersion); Console.WriteLine("IsDynamic:" + assembly.IsDynamic); Console.WriteLine("IsFullyTrusted:" + assembly.IsFullyTrusted); Console.WriteLine("Location:" + assembly.Location); Console.WriteLine("ReflectionOnly:" + assembly.ReflectionOnly); Console.WriteLine("SecurityRuleSet:" + assembly.SecurityRuleSet); }