1

Let's say I have installed a nuget in my (C#) project by using

<ItemGroup>
    <PackageReference Include="some.nuget" Version="1.2.3" />
</ItemGroup>

in an SDK-style project.

Let's say I have no access to any document describing that API or person who knows about it. I need to figure out on my own what public classes/methods there are.

How do I do that?

In other words: Where does an IDE (like Visual Studio or Visual Studio Code) get the data from, which it uses for IntelliSense?


In the installed nuget folder C:\Users\myUserName\.nuget\packages\some.nuget\1.2.3 is just some nuget metadata and the dll file. I know the information I need is inside the dll file, and I know that I can decompile it with some decompilation tool like ILSpy, but I doubt this is what the IDEs are doing. There must be a more straightforward way, right?

Kjara
  • 2,504
  • 15
  • 42
  • 1
    **Reflection** may be a good approach to iterate through classes in an assembly if I understand your question right. Check this question: https://stackoverflow.com/questions/1315665/c-list-all-classes-in-assembly – Ahmed Zaki Sep 19 '22 at 11:38
  • Reflection will provide you with a list of all classes with their names, all info will be gained easily. Check out the link to the question I provided in the first comment. – Ahmed Zaki Sep 19 '22 at 11:41

1 Answers1

4

Checking it programmatically

First you load up your dll:

var assembly = Assembly.LoadFrom(filename);

Then you can reflect all classes as is answered in: C#: List All Classes in Assembly

With that output you can reflect all methods as is answered in: Get private Properties/Method of base-class with reflection

Checking it manually

You are looking for the Object explorer. This can be found be typing "Object" in the general purpose search bar (ctrl + q) in Visual Studio and picking the one called "Object Browser" enter image description here

There you have an overview of all the projects and packages in your solution. If you for instance want to know what the AutoFixture NuGet package exposes you just click on it and browse. Nuget package in Object explorer

Ebbelink
  • 574
  • 3
  • 16
  • I am not looking for that object explorer. I want to know where/how the object explorer gets its data from, in order to show it to the user. – Kjara Sep 19 '22 at 13:09
  • Oh sorry I misunderstood the question. In that case your answer is, like @Ahmed Zaki already mentioned, Reflection. You can reflect all classes: https://stackoverflow.com/questions/1315665/c-list-all-classes-in-assembly Then reflect all methods: https://stackoverflow.com/questions/2267277/get-private-properties-method-of-base-class-with-reflection – Ebbelink Sep 19 '22 at 14:09
  • So does that mean IDEs really do reflection or even decompilation? If I do CTRL+click in Visual Studio Code or Visual Studio on a class from an installed nuget, I am shown a file that looks quite alike to something from ILSpy. I thought that an IDE just shows me a file that is already present on my computer after installing the nuget, not something it has generated/decompiled itself... – Kjara Sep 20 '22 at 18:49
  • In **German** Visual Studio the name is **Objektkatalog** instead of *Object Browser*. If you don't know this, it's difficult to find. – Beauty Jan 18 '23 at 08:05