Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out if a type is being referenced and hence may be potentially loaded at some point in time

I should know this but can't seem to remember.

How do I find out if a type is being used in an assembly (and not just that it exists in the assembly, which is the easy part).

class Dog { }

class Cat { }

class Rat { }

public object GetAnimal()
{
  if (today.Is(DayOfWeek.Monday))
  {
    return new Dog();
  }
  else
  {
    return new Cat();
  }
}

I want both Cat and Dog to show up as they can potentially be loaded at some time, but since Rat isn't being used, I don't want it to show up in my results.

like image 483
Water Cooler v2 Avatar asked May 13 '14 10:05

Water Cooler v2


People also ask

How can I check website memory usage?

Click the three dots at the top right of the browser, then hover over More tools, then select Task Manager. You can fast-track this process by pressing SHIFT+ESC on Windows. You should see a few processes running, the tabs you have open, and any extensions you've installed.

How do I free up memory in JavaScript?

To release memory, assign the global variable to null . window. users = null; I want to make this article as easy to understand as possible.


1 Answers

So to be clear the question is how do you find out if a class is used somewhere within the current project, which is a project that you have the source code for?

Assuming you are using Visual Studio, the easiest thing to do would be to load that project (not the entire multi-project solution) and then right-click on the class name and select "Find All References" (Shift + F12). The results will show each spot within the project that the class is used. In your case if the results are > 1 then the class is used somewhere within the project.

In your example the Rat class would only have one entry in the search results. The Cat and Dog classes would have two results.

like image 63
r2_118 Avatar answered Sep 27 '22 15:09

r2_118