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); }
本文来自博客园,作者:willamyao,转载请注明原文链接:https://www.cnblogs.com/robertyao/p/16962829.html
代码改变世界