C# 反射树
我试图找到类似于 Visual Studio 中内置的树视图的东西,可以让您遍历一个类。是否有一个基本的库/类,它基本上包含一个带有反射数据的树,该数据遍历一个类及其子类?我想要代码,我对单独的应用程序不感兴趣,
我认为用反射来实现不会那么困难,但我希望其他人已经做到了。
I"m try to find something similar to the treeview built into Visual Studio that lets you traverse a class. Is there a basic library/class that basically contains a tree with Reflected data that iterates through a class and its subclasses? I want code, I'm not interested in separate applications.
I don't think it would be that difficult to implement with reflection, but I'm hoping somebody else has already done it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只想迭代嵌套类,这里是一个示例
,也许您还需要一些有关方法、属性等的信息,在这种情况下您可以使用
If you just want ot iterate through nested class here is an example
Maybe you also want some info about Methods , Properties e.t.c in that case you can use
我知道您说过您需要代码,但让我首先提到一个名为 .Net Reflector 的工具。直到最近,它还是每个 .Net 开发人员完成您所谈论的事情的首选工具。几年前它被红门接管,他们最近表示将开始收费。
由于 red-gate 将对反射器收费,因此不少开源项目正在加紧开发替代品。如果我必须预测未来,我会说 ILSpy 成功的机会最大,因为它是由 SharpDevelop 团队推出的。
ILSpy:ILSpy 信息页面
I know that you stated that you want code, but let me start by mentioning a tool called .Net reflector. Until recently, it was the go-to tool for every .Net developer for doing what you are talking about. It was taken over by red-gate a few years back, and they recently stated that they are going to start charging for it.
Because red-gate is going to charge for reflector, quite a few open source projects are ramping up development for a replacement. If I had to predict the future, I'd say that ILSpy has the best chance of succeeding because its being put out by the SharpDevelop team.
ILSpy: ILSpy Info Page
搜索子类时,首先需要定义边界。您是否在特定程序集中搜索子类?如果是,那么这就是您需要的代码:
在上面的代码中,它在 System.DLL 中搜索 Nullable 的所有子类。要获取当前程序集中的子类,只需使用
Type
类提供大量信息即可获取当前程序集。Assembly
类也是如此。When searching for subclasses, first thing you need is to define boundaries. Are you searching for subclasses within a specific assembly? If yes, then this is the code you'll need:
In the code above, it searches for all subclasses of Nullable in System.DLL. To get the subclasses within the current assembly, simply get the current assembly using
The
Type
class provides a lot of information. So does theAssembly
class.