@@ -105,11 +105,6 @@ protected override void WriteSingleItem(
105105 . Where ( field => ! field . HasConstant )
106106 . OrderByDescending ( field => field . IsStatic )
107107 . ToList ( ) ;
108- foreach ( var field in fieldsList )
109- {
110- _context . SignaturesTable . GetOrCreateSignatureId ( field ) ;
111- _context . SignaturesTable . GetOrCreateSignatureId ( field . InitialValue ) ;
112- }
113108
114109 using ( var stream = new MemoryStream ( 6 ) )
115110 {
@@ -140,7 +135,7 @@ protected override void WriteSingleItem(
140135
141136 WriteMethodBodies ( item . Methods , item . Interfaces , writer ) ;
142137
143- _context . SignaturesTable . WriteDataType ( item , writer , false , true ) ;
138+ _context . SignaturesTable . WriteDataType ( item , writer , false , true , true ) ;
144139
145140 writer . WriteBytes ( stream . ToArray ( ) ) ;
146141 }
@@ -154,45 +149,56 @@ private void WriteClassFields(
154149 {
155150 ushort firstStaticFieldId = 0 ;
156151 var staticFieldsCount = 0 ;
157- foreach ( var field in fieldsList . Where ( item => item . IsStatic && ! item . IsLiteral ) )
152+ foreach ( var field in fieldsList . Where ( item => item . IsStatic ) )
158153 {
159154 ushort fieldReferenceId ;
160- _context . FieldsTable . TryGetFieldReferenceId ( field , true , out fieldReferenceId ) ;
161-
162- if ( staticFieldsCount == 0 )
155+ if ( _context . FieldsTable . TryGetFieldReferenceId ( field , false , out fieldReferenceId ) )
163156 {
164- // this is to be checked only on the 1st pass
165- firstStaticFieldId = Math . Min ( _context . FieldsTable . MaxFieldId , fieldReferenceId ) ;
166- }
157+ if ( staticFieldsCount == 0 )
158+ {
159+ // this is to be checked only on the 1st pass
160+ firstStaticFieldId = fieldReferenceId ;
161+ }
167162
168- _context . SignaturesTable . GetOrCreateSignatureId ( field ) ;
169- _context . StringTable . GetOrCreateStringId ( field . Name ) ;
163+ _context . SignaturesTable . GetOrCreateSignatureId ( field ) ;
164+ _context . SignaturesTable . GetOrCreateSignatureId ( field . InitialValue ) ;
165+ _context . StringTable . GetOrCreateStringId ( field . Name ) ;
170166
171- ++ staticFieldsCount ;
167+ ++ staticFieldsCount ;
168+ }
169+ else
170+ {
171+ // field ID not found!!
172+ }
172173 }
173174
174175 ushort firstInstanceFieldId = 0 ;
175176 var instanceFieldsCount = 0 ;
176- foreach ( var field in fieldsList . Where ( item => ! item . IsStatic && ! item . IsLiteral ) )
177+ foreach ( var field in fieldsList . Where ( item => ! item . IsStatic ) )
177178 {
178179 ushort fieldReferenceId ;
179- _context . FieldsTable . TryGetFieldReferenceId ( field , true , out fieldReferenceId ) ;
180-
181- if ( instanceFieldsCount == 0 )
180+ if ( _context . FieldsTable . TryGetFieldReferenceId ( field , false , out fieldReferenceId ) )
182181 {
183- // this is to be checked only on the 1st pass
184- firstInstanceFieldId = Math . Min ( _context . FieldsTable . MaxFieldId , fieldReferenceId ) ;
185- }
182+ if ( instanceFieldsCount == 0 )
183+ {
184+ // this is to be checked only on the 1st pass
185+ firstInstanceFieldId = fieldReferenceId ;
186+ }
186187
187- _context . SignaturesTable . GetOrCreateSignatureId ( field ) ;
188- _context . StringTable . GetOrCreateStringId ( field . Name ) ;
188+ _context . SignaturesTable . GetOrCreateSignatureId ( field ) ;
189+ _context . StringTable . GetOrCreateStringId ( field . Name ) ;
189190
190- ++ instanceFieldsCount ;
191+ ++ instanceFieldsCount ;
192+ }
193+ else
194+ {
195+ // field ID not found!!
196+ }
191197 }
192198
193199 if ( firstStaticFieldId < firstInstanceFieldId )
194200 {
195- if ( instanceFieldsCount > 0 && staticFieldsCount > 0 )
201+ if ( instanceFieldsCount > 0 && staticFieldsCount == 0 )
196202 {
197203 firstStaticFieldId = firstInstanceFieldId ;
198204 }
0 commit comments