private void LoadTypes() { m_allTypes = new LiftedList <TypeDefinition>( MetadataTable.TypeDef.RowCount(m_peFile), index => m_peFile.GetRow(new ZeroBasedIndex(index), MetadataTable.TypeDef), pRow => new TypeDefinition((TypeDefRow *)pRow, this), () => m_peFile.IsDisposed ); var nestedTypes = new LiftedValueTypeList <NestedTypeInfo>( MetadataTable.NestedClass.RowCount(m_peFile), index => m_peFile.GetRow(new ZeroBasedIndex(index), MetadataTable.NestedClass), x => { var pRow = (NestedClassRow *)x; return(new NestedTypeInfo( m_allTypes[((ZeroBasedIndex)(pRow->GetNestedClass(m_peFile))).Value], m_allTypes[((ZeroBasedIndex)(pRow->GetEnclosingClass(m_peFile))).Value] )); }, () => m_peFile.IsDisposed ); var enclosingTypes = nestedTypes.Select(x => x.NestedType.DeclaringType = x.EnclosingType).ToHashSet(); m_allTypes.GroupBy(x => x.DeclaringType).ForEach( x => (x.Key ?? (IMutableTypeContainer)this).Types = x.ToList().AsReadOnly() ); m_allTypes.Where( x => !enclosingTypes.Contains(x) ).ForEach( (IMutableTypeContainer x) => x.Types = new List <TypeDefinition>().AsReadOnly() ); }
unsafe void LoadModule(int index) { if (m_otherModules[index] == null) { lock (m_lockObject) { if (m_otherModules[index] == null) { var f = (FileRow *)m_mainFile.GetRow(new ZeroBasedIndex(index), MetadataTable.File); if ((f->Flags & FileAttributes.ContainsNoMetadata) != 0) { m_otherModules[index] = Module.CreateNonMetadataModule( m_assembly, m_mainFile.ReadSystemString( f->GetNameOffset(m_mainFile) ) ); } else { PEFile peFile = null; try { peFile = new PEFile(m_assembly, m_mainFile.ReadSystemString(f->GetNameOffset(m_mainFile))); m_otherModules[index] = peFile; } catch { if (peFile != null) { peFile.Dispose(); } throw; } } } } } }