Skip to content

Instantly share code, notes, and snippets.

@hoangitk
Forked from aelij/RoslynReflection.cs
Created October 31, 2017 03:15
Show Gist options
  • Save hoangitk/b6d53ae39fd1779f207b03609a4d4298 to your computer and use it in GitHub Desktop.
Save hoangitk/b6d53ae39fd1779f207b03609a4d4298 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