简体   繁体   English

检查class是否被使用?

[英]Check if class being used?

Simple problem, is it possible to check if a class is being used or not?简单的问题,是否可以检查是否正在使用 class?

class A { }
class B { }

class TestClass
{
    static void Main(string[] args)
    {
        var a = new A();
    }
}

I want to loop through all classes with reflection and get back that A is being used somewhere.我想通过反射遍历所有类,并返回A 正在某处使用 By "used" I mean there is a reference to it somewhere, it does not need to be loaded necessarily already. “使用过”是指在某处有对它的引用,不一定已经加载它。 In the same way Visual Studio show how many references an object has. Visual Studio 以同样的方式显示 object 有多少引用。

Short answer: My understanding is that unfortunately it is not possible to see if a class is used or not using reflection.简短回答:我的理解是,不幸的是,无法使用反射查看是否使用了 class I've got this hardcore solution tip using the Expression feature but I'm not sure that it is what I'm after.我有这个使用表达式功能的硬核解决方案提示,但我不确定它是否是我所追求的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM