GetType默认是取Global空间的Type,如果要取特定空间的Type,就要输入参数“xxxSpace.xxxType"。
如果我们要一个可以搜索全部命名空间的GetType,可以这样写
List<Type> GetTypes(string className)
{
List<Type> res = new List<Type>();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
var assemblyTypes = assembly.GetTypes();
for (int i = 0; i < assemblyTypes.Length; i++)
{
if (assemblyTypes[i].Name == className)
{
res.Add(assemblyTypes[i]);
}
}
}
return res;
}
博客介绍了GetType的使用,默认它取Global空间的Type,若要取特定空间的Type,需输入参数“xxxSpace.xxxType”,还提及可编写代码实现搜索全部命名空间的GetType。
1124





