本文介绍了如何获得命名空间内的所有类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- Taking一个特定的命名空间中的所有类
- Getting所有类型的命名空间通过反射
对不起。如何获得命名空间内的所有类?
Excuse me. How to get all classes within namespace?
推荐答案
您需要做的是倒退;列出的组件,然后检查每个类型的命名空间的所有类型:
You will need to do it "backwards"; list all the types in an assembly and then checking the namespace of each type:
using System.Reflection;
private Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
{
return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
}
使用示例:
Type[] typelist = GetTypesInNamespace(Assembly.GetExecutingAssembly(), "MyNamespace");
for (int i = 0; i < typelist.Length; i++)
{
Console.WriteLine(typelist[i].Name);
}
这篇关于如何获得命名空间内的所有类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!