如何使用反射来创建"反射机" [英] How to use reflection to create a "reflection machine"

查看:115
本文介绍了如何使用反射来创建"反射机"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OK(也许别人可以吗?)。

OK so that title sucks a little but I could not think of anything better (maybe someone else can?).

所以,我身边有一个主题的几个问题这里。我想要做的就是创建一个程序,可以采取一个对象,并使用反射来列出所有的属性,方法,构造等,然后我就可以在运行时操作这些对象进行测试,调试并找出到底是什么我的一些类/计划在做,而他们正在运行,(其中一些将是Windows服务,也许安装在机器上,而不是从VS调试运行)。

So I have a few questions around a subject here. What I want to do is create a program that can take an object and use reflection to list all its properties, methods, constructors etc. I can then manipulate these objects at runtime to test, debug and figure out exactly what some of my classes / programs are doing whilst they are running, (some of them will be windows services and maybe installed on the machine rather than running in debug from VS).

所以,我将提供一个钩子程序从本地机器(只)这个程序可以让主对象的实例,因此看到所有在其中运行的子对象。 (出于安全程序可能需要与ARG开始揭露那个勾)。

So I would provide a hook to the program that from the local machine (only) this program could get an instance of the main object and therefore see all the sub objects running in it. (for security the program may need to be started with an arg to expose that hook).

反思机将允许运行时处理和审讯。

The "reflection machine" would allow for runtime manipulation and interrogation.

这听起来可能吗?

请问程序必须提供一个钩子或者可以在反思机取一个EXE并且(如果它知道它使用的所有类),创建一个对象来使用?

Would the program have to provide a hook or could the "reflection machine" take an EXE and (if it knew all the classes it was using), create an object to use?

我知道你可以在运行时导入的DLL,使其知道各种类,但可以导入单个类? I.E.说我有项目'Y'未编译为一个DLL,但我想用反射机就可以了,我可以指出在该目录,并抢文件能够引用这些类?

I know you can import DLL's at runtime so that it knows about all sorts of classes, but can you import individual classes? I.E. Say I have project 'Y' that is not compiled to a DLL but I want to use the "reflection machine" on it, can I point at that directory and grab the files to be able to reference those classes?

编辑:我很想尝试和开发它我自己,但我已经有项目的一个长长的清单,我想这样做,并已经开始。为什么重新发明轮子的时候已经有一个伟大的选择可供选择

I would love to try and develop it my self but I already have a long list of projects I would like to do and have already started. Why reinvent the wheel when there is already a great selection to choose from.

推荐答案

试着看的 Crack.NET 。它是用来做什么的WPF / WinForms的运行操作和审讯,但源可用并且如果它已经不能满足你的需求可能是一个良好的开端。

Try looking at Crack.NET. It is used to do runtime manipulation and interrogation on WPF/WinForms but the source is available and might be a good start if it already doesn't meet your needs.

这篇关于如何使用反射来创建"反射机"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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