Replies: 1 comment
-
|
I have no idea what A rough (untested!!!!!!) sketch of what you need. using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
string assemblyPath = "path/to/your/assembly.dll";
var mainModule = new PEFile(assemblyPath);
var resolver = new UniversalAssemblyResolver(
assemblyPath,
throwOnError: true, // this useful for debugging so you immediately get alerted if a reference is missing due to a misconfiguration of the resolver
mainModule.DetectTargetFrameworkId());
// optional: add other directories containing references needed
//resolver.AddSearchDirectory(...);
var typeSystem = new DecompilerTypeSystem(mainModule, resolver);
foreach (ITypeDefinition type in typeSystem.MainModule.TypeDefinitions)
{
// this includes nested types as well
Console.WriteLine($" Type: {type.FullName}");
}Hope this helps, if you have further questions, feel free to ask. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is it worth using ILSpy, and how can I use it to perform an extensive scan of assemblies in a folder and analyze their types?
For example, in a given folder, I want to find all classes that inherit from a given class, find all implementers of a given interface, and find all properties whose type implements a given interface or is a collection of elements that implement an interface. Using regular Reflection is difficult because it is challenging to load all assemblies and their dependencies in the correct order, and there are always issues and exceptions when loading or reading types from an assembly. Despite this, the application works perfectly with the types that reflection fails to read.
I tried using ILSpy (
package ICSharpCode.Decompiler) viaSimpleCompiler.First, I downloaded all the assemblies from the folder via
new PEFile(...).Then I select among them the
PEFilethat has the maximum number of references (AssemblyReferences) from other pefiles.And then I pass one such
PEFileto the first parameter, and the rest to the second parameter of theSimpleCompilerconstructor.Then I run
SimpleCompiler.GetAllTypeDefinitions()and scan the types.Everything is not bad, except that the Generic types built into dotnet are defined as
Unknown, and their TypeArguments asdummy.Can anyone advise how to fully load the entire chain of dependencies, including the built-in types?
Beta Was this translation helpful? Give feedback.
All reactions