2

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.

abhi
  • 3,082
  • 6
  • 47
  • 73
  • Jon Skeet's answer from this SO question will help you : http://stackoverflow.com/questions/18905236/how-to-figure-out-dynamically-all-methods-with-custom-attribute – Jason Evans Jan 14 '14 at 15:09
  • @SonerGönül I am not sure if this is a true duplicate, since I am asking about the question from a VS 2012 feature perspective. – abhi Jan 14 '14 at 15:33

2 Answers2

4

You can use PowerShell to get a list of types/methods in a given assembly.

$AssemblyList = [System.AppDomain]::CurrentDomain.GetAssemblies();

foreach ($Type in $AssemblyList[5].GetTypes()) {
    $MethodList = $Type.GetMethods();
    foreach ($Method in $MethodList) {
        $Type.Name + ' ' + $Method.Name;
    }
}

You can also do a reflection-only load on a particular file path:

$Assembly = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom('c:\path\to\assembly.dll');

foreach ($Type in $Assembly.GetTypes()) {
    $MethodList = $Type.GetMethods();
    foreach ($Method in $MethodList) {
        $Type.Name + ' ' + $Method.Name;
    }
}
  • How PowerShell relates to OP question? – Konrad Kokosa Jan 14 '14 at 15:14
  • 1
    Read the title of the question: "How can I export the names of all the methods in an assembly?" Also, the OP's goal is: "I wish to export all these methods to a text file. –  Jan 14 '14 at 15:22
  • Hmm.. Read the tag C#. But maybe I'm missing something. Just asking... – Konrad Kokosa Jan 14 '14 at 15:24
  • The source code for the assembly is C#. – abhi Jan 14 '14 at 15:40
  • 1
    It doesn't matter what the source code for the assembly is. You can still use PowerShell to reflect over any valid .NET assembly. –  Jan 14 '14 at 15:41
  • @TrevorSullivan I was explaining the reason behind the tag. in Hindsight, I should have just tagged it .NET – abhi Jan 14 '14 at 15:58
2

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());
Liath
  • 9,913
  • 9
  • 51
  • 81
  • This is closest to what I need to do. I will modify this code to get the class names as well. Thank You. – abhi Jan 14 '14 at 15:34
  • Great, glad I could help. If you've resolved the issue can you mark one of the solutions as the answer? – Liath Jan 14 '14 at 15:36