0%

获取接口的全部实现类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
static void Main(string[] args)
{

InterfaceType(typeof(IInterface));
}
/// <summary>
/// 获取接口的全部实现类
/// </summary>
public static void InterfaceType(Type InterfaceTypeValue)
{
var types = AppDomain.CurrentDomain.GetAssemblies().
SelectMany(a => a.GetTypes().
Where(t => t.GetInterfaces().Contains(InterfaceTypeValue))).ToArray();

for (int i = 0; i < types.Length; i++)
{
Console.WriteLine(types[i].Name);
}
}