54 lines
1.0 KiB
C#
54 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
|
|
public static class TC
|
|
{
|
|
public static Type[] GetAllSubTypes(Type aBaseClass)
|
|
{
|
|
List<Type> list = new List<Type>();
|
|
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
|
Type[] array = null;
|
|
int i = 0;
|
|
Assembly[] array2 = assemblies;
|
|
for (int length = array2.Length; i < length; i++)
|
|
{
|
|
array = array2[i].GetTypes();
|
|
int j = 0;
|
|
Type[] array3 = array;
|
|
for (int length2 = array3.Length; j < length2; j++)
|
|
{
|
|
if (array3[j].IsSubclassOf(aBaseClass))
|
|
{
|
|
list.Add(array3[j]);
|
|
}
|
|
}
|
|
}
|
|
return list.ToArray();
|
|
}
|
|
|
|
public static Type GetType(Type t, string typeName)
|
|
{
|
|
int num = 0;
|
|
Type[] allSubTypes = GetAllSubTypes(t);
|
|
int length = allSubTypes.Length;
|
|
object result;
|
|
while (true)
|
|
{
|
|
if (num < length)
|
|
{
|
|
if (allSubTypes[num].Name == typeName)
|
|
{
|
|
result = allSubTypes[num];
|
|
break;
|
|
}
|
|
num++;
|
|
continue;
|
|
}
|
|
result = null;
|
|
break;
|
|
}
|
|
return (Type)result;
|
|
}
|
|
}
|