Last active
November 5, 2019 23:12
-
-
Save aelij/2921f76e2482530a91cb69d7e07e7e76 to your computer and use it in GitHub Desktop.
Reflection using Roslyn (without loading assemblies into the app domain)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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