@@ -42,7 +42,7 @@ public int GetHashCode(TypeDefinition item)
42
42
private IDictionary < uint , List < Tuple < uint , uint > > > _byteCodeOffsets =
43
43
new Dictionary < uint , List < Tuple < uint , uint > > > ( ) ;
44
44
45
- public List < TypeDefinition > TypeDefinitions { get ; }
45
+ public List < TypeDefinition > TypeDefinitions { get ; private set ; }
46
46
47
47
/// <summary>
48
48
/// Creates new instance of <see cref="nanoTypeDefinitionTable"/> object.
@@ -158,7 +158,12 @@ private void WriteClassFields(
158
158
{
159
159
ushort fieldReferenceId ;
160
160
_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
+ }
162
167
163
168
_context . SignaturesTable . GetOrCreateSignatureId ( field ) ;
164
169
_context . StringTable . GetOrCreateStringId ( field . Name ) ;
@@ -172,7 +177,12 @@ private void WriteClassFields(
172
177
{
173
178
ushort fieldReferenceId ;
174
179
_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
+ }
176
186
177
187
_context . SignaturesTable . GetOrCreateSignatureId ( field ) ;
178
188
_context . StringTable . GetOrCreateStringId ( field . Name ) ;
@@ -371,5 +381,23 @@ internal void ResetByteCodeOffsets()
371
381
{
372
382
_byteCodeOffsets = new Dictionary < uint , List < Tuple < uint , uint > > > ( ) ;
373
383
}
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
+ }
374
402
}
375
403
}
0 commit comments