D J
D J

Reputation: 7028

GetTypes in an assembly without using dependencies assemblies

I have a C# assembly but I dont have its dependencies assemblies.

Is there any way to GetTypes() of the .Net assembly without having its dependencies assembly.

 Assembly SampleAssembly;
 SampleAssembly = Assembly.LoadFrom(@"AnyExternal.dll");
 var mytypes = SampleAssembly.GetExportedTypes();

I have the AnyExternal.dll but I dont have the dependencies of it.

Is it possible.

Upvotes: 2

Views: 2592

Answers (2)

D J
D J

Reputation: 7028

I think that's what I was looking for.

http://www.codeproject.com/Articles/3262/A-NET-assembly-viewer

This viewer does not use any third party and can extract assembly infor.

Upvotes: 0

Dennis
Dennis

Reputation: 37760

Since you want just to discover type names, Mono.Cecil can help you:

var types = AssemblyDefinition
    .ReadAssembly("YourAssembly.dll")
    .MainModule
    .Types
    .Where(_ => _.IsPublic);

Note, that Where(_ => _.IsPublic) isn't a strict equivalent of Assembly.GetExportedTypes, since the last one also returns nested public types.

To add Mono.Cecil to your project, execute:

Install-Package Mono.Cecil

from Package Manager Console.

Upvotes: 3

Related Questions