private bool TryGetClass(ModuleDefinition module, string className, out ClassInfo clazz) { var visitor = new ModuleInfoVisitor(this, className); module.Accept(visitor); clazz = visitor.GetClassInfo(); return clazz != null; }
public override void VisitModuleDefinitionCollection(ModuleDefinitionCollection modules) { ModuleTable mt = m_tableReader.GetModuleTable(); if (mt == null || mt.Rows.Count != 1) { throw new ReflectionException("Can not read main module"); } ModuleRow mr = mt.Rows [0] as ModuleRow; string name = ReadString(mr.Name); ModuleDefinition main = new ModuleDefinition(name, m_asmDef, this, true); main.Mvid = m_streams.GuidHeap [mr.Mvid]; main.MetadataToken = new MetadataToken(TokenType.Module, 1); modules.Add(main); m_module = main; m_module.Accept(this); FileTable ftable = m_tableReader.GetFileTable(); if (ftable != null && ftable.Rows.Count > 0) { foreach (FileRow frow in ftable.Rows) { if (frow.Flags == Mono.Cecil.FileAttributes.ContainsMetaData) { name = ReadString(frow.Name); FileInfo location = new FileInfo(Path.Combine(m_img.FileInformation.DirectoryName, name)); if (!File.Exists(location.FullName)) { throw new FileNotFoundException("Module not found : " + name); } try { ImageReader module = ImageReader.Read(location.FullName); mt = module.Image.MetadataRoot.Streams.TablesHeap [ModuleTable.RId] as ModuleTable; if (mt == null || mt.Rows.Count != 1) { throw new ReflectionException("Can not read module : " + name); } mr = mt.Rows [0] as ModuleRow; ModuleDefinition modext = new ModuleDefinition(name, m_asmDef, new StructureReader(module, m_manifestOnly), false); modext.Mvid = module.Image.MetadataRoot.Streams.GuidHeap [mr.Mvid]; modules.Add(modext); } catch (ReflectionException) { throw; } catch (Exception e) { throw new ReflectionException("Can not read module : " + name, e); } } } } }
public override void VisitModuleDefinitionCollection (ModuleDefinitionCollection modules) { ModuleTable mt = m_tableReader.GetModuleTable (); if (mt == null || mt.Rows.Count != 1) throw new ReflectionException ("Can not read main module"); ModuleRow mr = mt [0]; string name = ReadString (mr.Name); ModuleDefinition main = new ModuleDefinition (name, m_asmDef, this, true); main.Mvid = m_streams.GuidHeap [mr.Mvid]; main.MetadataToken = new MetadataToken (TokenType.Module, 1); modules.Add (main); m_module = main; m_module.Accept (this); FileTable ftable = m_tableReader.GetFileTable (); if (ftable == null || ftable.Rows.Count == 0) return; foreach (FileRow frow in ftable.Rows) { if (frow.Flags != FileAttributes.ContainsMetaData) continue; name = ReadString (frow.Name); FileInfo location = new FileInfo ( m_img.FileInformation != null ? Path.Combine (m_img.FileInformation.DirectoryName, name) : name); if (!File.Exists (location.FullName)) throw new FileNotFoundException ("Module not found : " + name); try { ImageReader module = ImageReader.Read (location.FullName); mt = module.Image.MetadataRoot.Streams.TablesHeap [ModuleTable.RId] as ModuleTable; if (mt == null || mt.Rows.Count != 1) throw new ReflectionException ("Can not read module : " + name); mr = mt [0]; ModuleDefinition modext = new ModuleDefinition (name, m_asmDef, new StructureReader (module, m_manifestOnly), false); modext.Mvid = module.Image.MetadataRoot.Streams.GuidHeap [mr.Mvid]; modules.Add (modext); modext.Accept (this); } catch (ReflectionException) { throw; } catch (Exception e) { throw new ReflectionException ("Can not read module : " + name, e); } } }