Frage

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.

War es hilfreich?

Lösung

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());

Andere Tipps

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;
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top