@@ -42,7 +42,7 @@ public int GetHashCode(TypeDefinition item)
4242 private IDictionary < uint , List < Tuple < uint , uint > > > _byteCodeOffsets =
4343 new Dictionary < uint , List < Tuple < uint , uint > > > ( ) ;
4444
45- public List < TypeDefinition > TypeDefinitions { get ; }
45+ public List < TypeDefinition > TypeDefinitions { get ; private set ; }
4646
4747 /// <summary>
4848 /// Creates new instance of <see cref="nanoTypeDefinitionTable"/> object.
@@ -158,7 +158,12 @@ private void WriteClassFields(
158158 {
159159 ushort fieldReferenceId ;
160160 _context . FieldsTable . TryGetFieldReferenceId ( field , true , out fieldReferenceId ) ;
161- firstStaticFieldId = Math . Min ( _context . FieldsTable . MaxFieldId , fieldReferenceId ) ;
161+
162+ if ( staticFieldsCount == 0 )
163+ {
164+ // this is to be checked only on the 1st pass
165+ firstStaticFieldId = Math . Min ( _context . FieldsTable . MaxFieldId , fieldReferenceId ) ;
166+ }
162167
163168 _context . SignaturesTable . GetOrCreateSignatureId ( field ) ;
164169 _context . StringTable . GetOrCreateStringId ( field . Name ) ;
@@ -172,7 +177,12 @@ private void WriteClassFields(
172177 {
173178 ushort fieldReferenceId ;
174179 _context . FieldsTable . TryGetFieldReferenceId ( field , true , out fieldReferenceId ) ;
175- firstInstanceFieldId = Math . Min ( _context . FieldsTable . MaxFieldId , fieldReferenceId ) ;
180+
181+ if ( instanceFieldsCount == 0 )
182+ {
183+ // this is to be checked only on the 1st pass
184+ firstInstanceFieldId = Math . Min ( _context . FieldsTable . MaxFieldId , fieldReferenceId ) ;
185+ }
176186
177187 _context . SignaturesTable . GetOrCreateSignatureId ( field ) ;
178188 _context . StringTable . GetOrCreateStringId ( field . Name ) ;
@@ -371,5 +381,23 @@ internal void ResetByteCodeOffsets()
371381 {
372382 _byteCodeOffsets = new Dictionary < uint , List < Tuple < uint , uint > > > ( ) ;
373383 }
384+
385+ public override void RemoveUnusedItems ( HashSet < MetadataToken > set )
386+ {
387+ base . RemoveUnusedItems ( set ) ;
388+
389+ // remove
390+ // build a collection of the current items that are present in the used items set
391+ List < TypeDefinition > usedItems = new List < TypeDefinition > ( ) ;
392+
393+ foreach ( var item in TypeDefinitions
394+ . Where ( item => set . Contains ( item . MetadataToken ) ) )
395+ {
396+ usedItems . Add ( item ) ;
397+ }
398+
399+ // replace existing collection
400+ TypeDefinitions = usedItems ;
401+ }
374402 }
375403}
0 commit comments