简体   繁体   中英

Check if class being used?

Simple problem, is it possible to check if a class is being used or not?

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. 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.

Short answer: My understanding is that unfortunately it is not possible to see if a class is used or not using reflection. I've got this hardcore solution tip using the Expression feature but I'm not sure that it is what I'm after.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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