Example #1
0
        public AnalysisNet.Assembly ExtractAssembly()
        {
            // create empty assembly
            AnalysisNet.Assembly assembly = new AnalysisNet.Assembly(module.Assembly.Name.Name);

            // populate assembly references
            assembly.References.AddRange(ExtractAssemblyReferences());

            // create root namespace
            // every other namespace is created while processing each cecil type definition
            assembly.RootNamespace = new AnalysisNet.Namespace(string.Empty)
            {
                ContainingAssembly = new AnalysisNet.AssemblyReference(assembly.Name)
            };
            namespaces[string.Empty] = assembly.RootNamespace;

            // re use the same object because it contains a cache inside
            // but be sure typeExtractor is not referenced forever
            // otherwise we would not dipose cecil code model
            TypeExtractor typeExtractor = new TypeExtractor(host);

            // if cecilType is a nested type, we guarantee that we have already visited its declaring type
            foreach (Cecil.TypeDefinition cecilType in module.TraverseTypes())
            {
                ExtractTypeDefinition(cecilType, assembly, typeExtractor);
            }

            return(assembly);
        }