问题描述
使用的System.Reflection,我可以从一个特定的类
Using System.Reflection, I can get all methods from a specific class
我需要知道什么是对这些方法的参考文献的所有方法。例如:在Visual Studio中,如果你想要特定对象的引用
I need know what are the references to these methods. For example: in Visual Studio, if you want the references of specific object
- 右键单击对象,选择查找所有引用
- Visual Studio中显示此所选对象
我要做出同样的参考,但是从代码反射或另一种方式。
I want make the same, but from code with reflection or another way.
我能做到这一点?
推荐答案
这不能与反思完成。反思是用于检查元数据和组件的工具。为了找到一个给定的方法/类型的所有引用,你需要检查程序集的基本IL。反射只有非常有限的能力,IL(只返回它作为一个字节数组)。你需要定制检查的字节流,以收集有关它的引用任何上下文。
This cannot be done with reflection. Reflection is a tool for inspecting metadata and assemblies. In order to find all references to a given method / type, you'd need to inspect the underlying IL of an assembly. Reflection only has very limited IL capabilities (simply returns it as a byte array). You'll need to custom inspect that byte stream in order to gather any context about what it's referencing.
这篇关于我怎样才能用反射+ C#所有参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!