We all know how useful MonoDevelop’s ‘Find References’ feature is for certain scenarios where you’d want to quickly find all scripts and EXACT lines in the whole solution that reference or call a specific method/function.
I just want to get your ideas on how one could accomplish this in Unity. I need to create a tool that essentially provides the reverse of CollectDependencies (Unity - Scripting API: EditorUtility.CollectDependencies), and yet, does so on a lower level (i.e. finding exact lines of code in the whole project that call the function).
By the way, the closest solution I could find is probably this: http://wiki.unity3d.com/index.php/UnityAssetXrefs. That utility, however, doesn't allow me to specify which function I wanted to find references of. Only the class/script. It's close though...
Then use GetAssemblies to get a list of all loaded assemblies. You might want to filter that list as you won’t find references to your own classes / methods / fields in mscorlib.dll, UnityEngine.dll, … and searching the whole appdomain would probably take hours
On the remaining assemblies you would call GetTypes to get a list of all classes defines in that assembly. So you end up with a huge list of System.Type references.
On each type you would call GetMethods to get all MethodInfos of all methods in those classes. Keep in mind to use the BindingFlags version if you also want to search private / static methods
The MethodInfo class (or to be more precise it’s base class MethodBase) has a method called GetMethodBody which returns a MethodBody object
that is a pretty extensive answer Bunny83. Thanks! I will try this out asap and most probably will come back to this question to check your answer as the accepted one. thumbsup
after reading stuff on .NET, IL, and Reflection, I cannot believe I made it all the way up to this point in my coding life where I have not yet (not even once) dived into all this which seems pretty straightforward and easy as vexe points out... I feel like a jackass, lol... well, something new to learn everyday!
By the way, the closest solution I could find is probably this: http://wiki.unity3d.com/index.php/UnityAssetXrefs. That utility, however, doesn't allow me to specify which function I wanted to find references of. Only the class/script. It's close though...
– zannghast