c# 反射获取所有实现接口的类,解决未能加载文件或程序集的问题

Type[] types = AppDomain.CurrentDomain.GetAssemblies()
                        .SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IConfigConvert))))
                        .ToArray();
            Assembly assembly = Assembly.GetExecutingAssembly(); // 获取当前程序集
            foreach (Type type in types)
            {
                string name = type.FullName;
                IConfigConvert iconvert = (IConfigConvert)assembly.CreateInstance(name);
            }

  

posted @ 2022-12-07 13:28  willamyao  阅读(47)  评论(0编辑  收藏  举报