Search code examples
c#visual-studio-2012reflectionobjectbrowser

How can I export the names of all the methods in an assembly?


I am able to see all the methods in a referenced library in my object browser. I wish to export all these methods to a text file.object browser

I also have access to dotPeek but I could not locate any export functionality in that software.


Solution

  • I've got to admit I'm not sure how you could do it in Visual Studio, but programatically you can use reflection:

    System.IO.File.WriteAllLines(myFileName,
                    System.Reflection.Assembly.LoadFile(myDllPath)
                        .GetType(className)
                        .GetMethods()
                        .Select(m => m.Name)
                        .ToArray());
    

    ETA:

    I'm not 100% if you want the methods in the screenshot or all the methods in the DLL so I've updated with the second variant:

     System.IO.File.WriteAllLines(myFileName,
                    System.Reflection.Assembly.LoadFile(myDllPath)
                        .GetTypes()                    
                        .SelectMany(t => t.GetMethods())
                        .Select(m => m.Name)
                        .ToArray());