让所有类型的通过反射命名空间 [英] Getting all types in a namespace via reflection

查看:177
本文介绍了让所有类型的通过反射命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中获取的所有类在命名空间通过反射?

How do you get all the classes in a namespace through reflection in C#?

推荐答案

随着code打印在指定的命名空间名称在当前汇编中定义。
正如其他人所指出的,一个命名空间可以分散在不同的模块之间,所以你需要获得组件列表第一位。

Following code prints names of classes in specified namespace defined in current assembly.
As other guys pointed out, a namespace can be scattered between different modules, so you need to get a list of assemblies first.

string @namespace = "...";

var q = from t in Assembly.GetExecutingAssembly().GetTypes()
        where t.IsClass && t.Namespace == @namespace
        select t;
q.ToList().ForEach(t => Console.WriteLine(t.Name));

这篇关于让所有类型的通过反射命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆