We are currently in the process of converting the website to the new design. Some pages, like this one, are still broken. We appreciate your patience.
Handmade Network»Forums
251 posts
How to get declarations from a c# dll?
Edited by longtran2904 on

When you use "go to definition" in a C# project in Visual Studio, it will generate a temporary cs file "from metadata" containing classes/functions declarations. Afaik, Visual Studio only needs a DLL or Exe file to do this. Are there any tools or visual studio options to generate these cs files for a chosen dll? I want to replace VS with other editors but really need this functionality (only need this for syntax highlighting, I plan to generate all the declarations into a bunch of cs files and include them).

Mārtiņš Možeiko
2583 posts / 2 projects
How to get declarations from a c# dll?

What do you mean by "include them"? You don't need to include any C# files to compile. You just reference existing .dll modules in compiler arguments.

If you want to access contents of dll/exe programmatically then you can use Assembly.Load method from System.Reflection. It will load assembly and will let you access all the contents and do whatever you want - see GetModules() and then for each module do GetTypes() and so on... With built-in reflection API you can get 100% contents of any .NET Assembly.

Or you can use something like ILSpy to decompile dll/exe and see all the contents of modules, including decompiled code, be it C#. It has nice Visual Studio plugins that allow stepping into decompile C# code so you can easily debug .dll files that you don't have source access to. It is very useful in VS.

251 posts
How to get declarations from a c# dll?
Edited by longtran2904 on
Replying to mmozeiko (#29220)

What do you mean by "include them"? You don't need to include any C# files to compile. You just reference existing .dll modules in compiler arguments.

I meant I only need it for syntax highlighting. By having the declarations, my code editor (not an ide or compiler) can know which identifier is a type and whatnot. "include them" just meant having those files recognized by the editor.

I also don't need to see decompiled code or debugging/stepping into code, just the declaration of classes and functions, like what happens when you use "go to definition" in VS and it creates a temporary "header" file.

I was hoping for something like: if you use this command in VS or this program, it will automatically generate all the types and functions for you into a C# file. Because as I said, VS is already doing that, but the problems are it's temporary and I need to manually "go to definition" for each type.

Edit: Just checked out ILSpy, and it seems like the program is doing what I want. Is there a way to export all the definitions to a C# source file?