Skip to content

Instantly share code, notes, and snippets.

@aelij
Last active November 5, 2019 23:12
Show Gist options
  • Save aelij/2921f76e2482530a91cb69d7e07e7e76 to your computer and use it in GitHub Desktop.
Save aelij/2921f76e2482530a91cb69d7e07e7e76 to your computer and use it in GitHub Desktop.
Reflection using Roslyn (without loading assemblies into the app domain)
var compilation = CSharpCompilation.Create("C")
.AddReferences(MetadataReference.CreateFromFile(pathToAssembly));
foreach (var type in
from assemblySymbol in compilation.SourceModule.ReferencedAssemblySymbols
from module in assemblySymbol.Modules
from n in module.GlobalNamespace.GetMembers()
where n.IsNamespace
from type in n.GetTypeMembers()
select type)
{
Console.WriteLine(type);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment