Merge branch 'cecil-light'
[mono.git] / mcs / tools / cil-strip / Mono.Cecil.Metadata / MetadataRowWriter.cs
1 //
2 // MetadataRowWriter.cs
3 //
4 // Author:
5 //   Jb Evain (jbevain@gmail.com)
6 //
7 // Generated by /CodeGen/cecil-gen.rb do not edit
8 // Sat Feb 16 23:24:17 +0100 2008
9 //
10 // (C) 2005 Jb Evain
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 namespace Mono.Cecil.Metadata {
33
34         using System;
35         using System.Collections;
36
37         using Mono.Cecil.Binary;
38
39         sealed class MetadataRowWriter : BaseMetadataRowVisitor {
40
41                 MetadataRoot m_root;
42                 MemoryBinaryWriter m_binaryWriter;
43
44                 Utilities.TableRowCounter m_counter;
45                 int [] m_ciCache;
46
47                 int m_blobHeapIdxSz;
48                 int m_stringsHeapIdxSz;
49                 int m_guidHeapIdxSz;
50
51                 public MetadataRowWriter (MetadataTableWriter mtwv)
52                 {
53                         m_binaryWriter = mtwv.GetWriter ();
54                         m_root = mtwv.GetMetadataRoot ();
55                         m_ciCache = new int [13];
56                         m_counter = new Utilities.TableRowCounter (GetNumberOfRows);
57                 }
58
59                 void WriteBlobPointer (uint pointer)
60                 {
61                         WriteByIndexSize (pointer, m_blobHeapIdxSz);
62                 }
63
64                 void WriteStringPointer (uint pointer)
65                 {
66                         WriteByIndexSize (pointer, m_stringsHeapIdxSz);
67                 }
68
69                 void WriteGuidPointer (uint pointer)
70                 {
71                         WriteByIndexSize (pointer, m_guidHeapIdxSz);
72                 }
73
74                 void WriteTablePointer (uint pointer, int rid)
75                 {
76                         WriteByIndexSize (pointer, GetNumberOfRows (rid) < (1 << 16) ? 2 : 4);
77                 }
78
79                 void WriteMetadataToken (MetadataToken token, CodedIndex ci)
80                 {
81                         WriteByIndexSize (Utilities.CompressMetadataToken (ci, token),
82                                 Utilities.GetCodedIndexSize (ci, m_counter, m_ciCache));
83                 }
84
85                 int GetNumberOfRows (int rid)
86                 {
87                         IMetadataTable t = m_root.Streams.TablesHeap [rid];
88                         if (t == null || t.Rows == null)
89                                 return 0;
90                         return t.Rows.Count;
91                 }
92
93                 void WriteByIndexSize (uint value, int size)
94                 {
95                         if (size == 4)
96                                 m_binaryWriter.Write (value);
97                         else if (size == 2)
98                                 m_binaryWriter.Write ((ushort) value);
99                         else
100                                 throw new MetadataFormatException ("Non valid size for indexing");
101                 }
102
103                 public AssemblyRow CreateAssemblyRow (AssemblyHashAlgorithm _hashAlgId, ushort _majorVersion, ushort _minorVersion, ushort _buildNumber, ushort _revisionNumber, AssemblyFlags _flags, uint _publicKey, uint _name, uint _culture)
104                 {
105                         AssemblyRow row = new AssemblyRow ();
106                         row.HashAlgId = _hashAlgId;
107                         row.MajorVersion = _majorVersion;
108                         row.MinorVersion = _minorVersion;
109                         row.BuildNumber = _buildNumber;
110                         row.RevisionNumber = _revisionNumber;
111                         row.Flags = _flags;
112                         row.PublicKey = _publicKey;
113                         row.Name = _name;
114                         row.Culture = _culture;
115                         return row;
116                 }
117
118                 public AssemblyOSRow CreateAssemblyOSRow (uint _oSPlatformID, uint _oSMajorVersion, uint _oSMinorVersion)
119                 {
120                         AssemblyOSRow row = new AssemblyOSRow ();
121                         row.OSPlatformID = _oSPlatformID;
122                         row.OSMajorVersion = _oSMajorVersion;
123                         row.OSMinorVersion = _oSMinorVersion;
124                         return row;
125                 }
126
127                 public AssemblyProcessorRow CreateAssemblyProcessorRow (uint _processor)
128                 {
129                         AssemblyProcessorRow row = new AssemblyProcessorRow ();
130                         row.Processor = _processor;
131                         return row;
132                 }
133
134                 public AssemblyRefRow CreateAssemblyRefRow (ushort _majorVersion, ushort _minorVersion, ushort _buildNumber, ushort _revisionNumber, AssemblyFlags _flags, uint _publicKeyOrToken, uint _name, uint _culture, uint _hashValue)
135                 {
136                         AssemblyRefRow row = new AssemblyRefRow ();
137                         row.MajorVersion = _majorVersion;
138                         row.MinorVersion = _minorVersion;
139                         row.BuildNumber = _buildNumber;
140                         row.RevisionNumber = _revisionNumber;
141                         row.Flags = _flags;
142                         row.PublicKeyOrToken = _publicKeyOrToken;
143                         row.Name = _name;
144                         row.Culture = _culture;
145                         row.HashValue = _hashValue;
146                         return row;
147                 }
148
149                 public AssemblyRefOSRow CreateAssemblyRefOSRow (uint _oSPlatformID, uint _oSMajorVersion, uint _oSMinorVersion, uint _assemblyRef)
150                 {
151                         AssemblyRefOSRow row = new AssemblyRefOSRow ();
152                         row.OSPlatformID = _oSPlatformID;
153                         row.OSMajorVersion = _oSMajorVersion;
154                         row.OSMinorVersion = _oSMinorVersion;
155                         row.AssemblyRef = _assemblyRef;
156                         return row;
157                 }
158
159                 public AssemblyRefProcessorRow CreateAssemblyRefProcessorRow (uint _processor, uint _assemblyRef)
160                 {
161                         AssemblyRefProcessorRow row = new AssemblyRefProcessorRow ();
162                         row.Processor = _processor;
163                         row.AssemblyRef = _assemblyRef;
164                         return row;
165                 }
166
167                 public ClassLayoutRow CreateClassLayoutRow (ushort _packingSize, uint _classSize, uint _parent)
168                 {
169                         ClassLayoutRow row = new ClassLayoutRow ();
170                         row.PackingSize = _packingSize;
171                         row.ClassSize = _classSize;
172                         row.Parent = _parent;
173                         return row;
174                 }
175
176                 public ConstantRow CreateConstantRow (ElementType _type, MetadataToken _parent, uint _value)
177                 {
178                         ConstantRow row = new ConstantRow ();
179                         row.Type = _type;
180                         row.Parent = _parent;
181                         row.Value = _value;
182                         return row;
183                 }
184
185                 public CustomAttributeRow CreateCustomAttributeRow (MetadataToken _parent, MetadataToken _type, uint _value)
186                 {
187                         CustomAttributeRow row = new CustomAttributeRow ();
188                         row.Parent = _parent;
189                         row.Type = _type;
190                         row.Value = _value;
191                         return row;
192                 }
193
194                 public DeclSecurityRow CreateDeclSecurityRow (SecurityAction _action, MetadataToken _parent, uint _permissionSet)
195                 {
196                         DeclSecurityRow row = new DeclSecurityRow ();
197                         row.Action = _action;
198                         row.Parent = _parent;
199                         row.PermissionSet = _permissionSet;
200                         return row;
201                 }
202
203                 public EventRow CreateEventRow (EventAttributes _eventFlags, uint _name, MetadataToken _eventType)
204                 {
205                         EventRow row = new EventRow ();
206                         row.EventFlags = _eventFlags;
207                         row.Name = _name;
208                         row.EventType = _eventType;
209                         return row;
210                 }
211
212                 public EventMapRow CreateEventMapRow (uint _parent, uint _eventList)
213                 {
214                         EventMapRow row = new EventMapRow ();
215                         row.Parent = _parent;
216                         row.EventList = _eventList;
217                         return row;
218                 }
219
220                 public EventPtrRow CreateEventPtrRow (uint _event)
221                 {
222                         EventPtrRow row = new EventPtrRow ();
223                         row.Event = _event;
224                         return row;
225                 }
226
227                 public ExportedTypeRow CreateExportedTypeRow (TypeAttributes _flags, uint _typeDefId, uint _typeName, uint _typeNamespace, MetadataToken _implementation)
228                 {
229                         ExportedTypeRow row = new ExportedTypeRow ();
230                         row.Flags = _flags;
231                         row.TypeDefId = _typeDefId;
232                         row.TypeName = _typeName;
233                         row.TypeNamespace = _typeNamespace;
234                         row.Implementation = _implementation;
235                         return row;
236                 }
237
238                 public FieldRow CreateFieldRow (FieldAttributes _flags, uint _name, uint _signature)
239                 {
240                         FieldRow row = new FieldRow ();
241                         row.Flags = _flags;
242                         row.Name = _name;
243                         row.Signature = _signature;
244                         return row;
245                 }
246
247                 public FieldLayoutRow CreateFieldLayoutRow (uint _offset, uint _field)
248                 {
249                         FieldLayoutRow row = new FieldLayoutRow ();
250                         row.Offset = _offset;
251                         row.Field = _field;
252                         return row;
253                 }
254
255                 public FieldMarshalRow CreateFieldMarshalRow (MetadataToken _parent, uint _nativeType)
256                 {
257                         FieldMarshalRow row = new FieldMarshalRow ();
258                         row.Parent = _parent;
259                         row.NativeType = _nativeType;
260                         return row;
261                 }
262
263                 public FieldPtrRow CreateFieldPtrRow (uint _field)
264                 {
265                         FieldPtrRow row = new FieldPtrRow ();
266                         row.Field = _field;
267                         return row;
268                 }
269
270                 public FieldRVARow CreateFieldRVARow (RVA _rVA, uint _field)
271                 {
272                         FieldRVARow row = new FieldRVARow ();
273                         row.RVA = _rVA;
274                         row.Field = _field;
275                         return row;
276                 }
277
278                 public FileRow CreateFileRow (FileAttributes _flags, uint _name, uint _hashValue)
279                 {
280                         FileRow row = new FileRow ();
281                         row.Flags = _flags;
282                         row.Name = _name;
283                         row.HashValue = _hashValue;
284                         return row;
285                 }
286
287                 public GenericParamRow CreateGenericParamRow (ushort _number, GenericParameterAttributes _flags, MetadataToken _owner, uint _name)
288                 {
289                         GenericParamRow row = new GenericParamRow ();
290                         row.Number = _number;
291                         row.Flags = _flags;
292                         row.Owner = _owner;
293                         row.Name = _name;
294                         return row;
295                 }
296
297                 public GenericParamConstraintRow CreateGenericParamConstraintRow (uint _owner, MetadataToken _constraint)
298                 {
299                         GenericParamConstraintRow row = new GenericParamConstraintRow ();
300                         row.Owner = _owner;
301                         row.Constraint = _constraint;
302                         return row;
303                 }
304
305                 public ImplMapRow CreateImplMapRow (PInvokeAttributes _mappingFlags, MetadataToken _memberForwarded, uint _importName, uint _importScope)
306                 {
307                         ImplMapRow row = new ImplMapRow ();
308                         row.MappingFlags = _mappingFlags;
309                         row.MemberForwarded = _memberForwarded;
310                         row.ImportName = _importName;
311                         row.ImportScope = _importScope;
312                         return row;
313                 }
314
315                 public InterfaceImplRow CreateInterfaceImplRow (uint _class, MetadataToken _interface)
316                 {
317                         InterfaceImplRow row = new InterfaceImplRow ();
318                         row.Class = _class;
319                         row.Interface = _interface;
320                         return row;
321                 }
322
323                 public ManifestResourceRow CreateManifestResourceRow (uint _offset, ManifestResourceAttributes _flags, uint _name, MetadataToken _implementation)
324                 {
325                         ManifestResourceRow row = new ManifestResourceRow ();
326                         row.Offset = _offset;
327                         row.Flags = _flags;
328                         row.Name = _name;
329                         row.Implementation = _implementation;
330                         return row;
331                 }
332
333                 public MemberRefRow CreateMemberRefRow (MetadataToken _class, uint _name, uint _signature)
334                 {
335                         MemberRefRow row = new MemberRefRow ();
336                         row.Class = _class;
337                         row.Name = _name;
338                         row.Signature = _signature;
339                         return row;
340                 }
341
342                 public MethodRow CreateMethodRow (RVA _rVA, MethodImplAttributes _implFlags, MethodAttributes _flags, uint _name, uint _signature, uint _paramList)
343                 {
344                         MethodRow row = new MethodRow ();
345                         row.RVA = _rVA;
346                         row.ImplFlags = _implFlags;
347                         row.Flags = _flags;
348                         row.Name = _name;
349                         row.Signature = _signature;
350                         row.ParamList = _paramList;
351                         return row;
352                 }
353
354                 public MethodImplRow CreateMethodImplRow (uint _class, MetadataToken _methodBody, MetadataToken _methodDeclaration)
355                 {
356                         MethodImplRow row = new MethodImplRow ();
357                         row.Class = _class;
358                         row.MethodBody = _methodBody;
359                         row.MethodDeclaration = _methodDeclaration;
360                         return row;
361                 }
362
363                 public MethodPtrRow CreateMethodPtrRow (uint _method)
364                 {
365                         MethodPtrRow row = new MethodPtrRow ();
366                         row.Method = _method;
367                         return row;
368                 }
369
370                 public MethodSemanticsRow CreateMethodSemanticsRow (MethodSemanticsAttributes _semantics, uint _method, MetadataToken _association)
371                 {
372                         MethodSemanticsRow row = new MethodSemanticsRow ();
373                         row.Semantics = _semantics;
374                         row.Method = _method;
375                         row.Association = _association;
376                         return row;
377                 }
378
379                 public MethodSpecRow CreateMethodSpecRow (MetadataToken _method, uint _instantiation)
380                 {
381                         MethodSpecRow row = new MethodSpecRow ();
382                         row.Method = _method;
383                         row.Instantiation = _instantiation;
384                         return row;
385                 }
386
387                 public ModuleRow CreateModuleRow (ushort _generation, uint _name, uint _mvid, uint _encId, uint _encBaseId)
388                 {
389                         ModuleRow row = new ModuleRow ();
390                         row.Generation = _generation;
391                         row.Name = _name;
392                         row.Mvid = _mvid;
393                         row.EncId = _encId;
394                         row.EncBaseId = _encBaseId;
395                         return row;
396                 }
397
398                 public ModuleRefRow CreateModuleRefRow (uint _name)
399                 {
400                         ModuleRefRow row = new ModuleRefRow ();
401                         row.Name = _name;
402                         return row;
403                 }
404
405                 public NestedClassRow CreateNestedClassRow (uint _nestedClass, uint _enclosingClass)
406                 {
407                         NestedClassRow row = new NestedClassRow ();
408                         row.NestedClass = _nestedClass;
409                         row.EnclosingClass = _enclosingClass;
410                         return row;
411                 }
412
413                 public ParamRow CreateParamRow (ParameterAttributes _flags, ushort _sequence, uint _name)
414                 {
415                         ParamRow row = new ParamRow ();
416                         row.Flags = _flags;
417                         row.Sequence = _sequence;
418                         row.Name = _name;
419                         return row;
420                 }
421
422                 public ParamPtrRow CreateParamPtrRow (uint _param)
423                 {
424                         ParamPtrRow row = new ParamPtrRow ();
425                         row.Param = _param;
426                         return row;
427                 }
428
429                 public PropertyRow CreatePropertyRow (PropertyAttributes _flags, uint _name, uint _type)
430                 {
431                         PropertyRow row = new PropertyRow ();
432                         row.Flags = _flags;
433                         row.Name = _name;
434                         row.Type = _type;
435                         return row;
436                 }
437
438                 public PropertyMapRow CreatePropertyMapRow (uint _parent, uint _propertyList)
439                 {
440                         PropertyMapRow row = new PropertyMapRow ();
441                         row.Parent = _parent;
442                         row.PropertyList = _propertyList;
443                         return row;
444                 }
445
446                 public PropertyPtrRow CreatePropertyPtrRow (uint _property)
447                 {
448                         PropertyPtrRow row = new PropertyPtrRow ();
449                         row.Property = _property;
450                         return row;
451                 }
452
453                 public StandAloneSigRow CreateStandAloneSigRow (uint _signature)
454                 {
455                         StandAloneSigRow row = new StandAloneSigRow ();
456                         row.Signature = _signature;
457                         return row;
458                 }
459
460                 public TypeDefRow CreateTypeDefRow (TypeAttributes _flags, uint _name, uint _namespace, MetadataToken _extends, uint _fieldList, uint _methodList)
461                 {
462                         TypeDefRow row = new TypeDefRow ();
463                         row.Flags = _flags;
464                         row.Name = _name;
465                         row.Namespace = _namespace;
466                         row.Extends = _extends;
467                         row.FieldList = _fieldList;
468                         row.MethodList = _methodList;
469                         return row;
470                 }
471
472                 public TypeRefRow CreateTypeRefRow (MetadataToken _resolutionScope, uint _name, uint _namespace)
473                 {
474                         TypeRefRow row = new TypeRefRow ();
475                         row.ResolutionScope = _resolutionScope;
476                         row.Name = _name;
477                         row.Namespace = _namespace;
478                         return row;
479                 }
480
481                 public TypeSpecRow CreateTypeSpecRow (uint _signature)
482                 {
483                         TypeSpecRow row = new TypeSpecRow ();
484                         row.Signature = _signature;
485                         return row;
486                 }
487
488                 public override void VisitRowCollection (RowCollection coll)
489                 {
490                         m_blobHeapIdxSz = m_root.Streams.BlobHeap != null ?
491                                 m_root.Streams.BlobHeap.IndexSize : 2;
492                         m_stringsHeapIdxSz = m_root.Streams.StringsHeap != null ?
493                                 m_root.Streams.StringsHeap.IndexSize : 2;
494                         m_guidHeapIdxSz = m_root.Streams.GuidHeap != null ?
495                                 m_root.Streams.GuidHeap.IndexSize : 2;
496                 }
497
498                 public override void VisitAssemblyRow (AssemblyRow row)
499                 {
500                         m_binaryWriter.Write ((uint) row.HashAlgId);
501                         m_binaryWriter.Write (row.MajorVersion);
502                         m_binaryWriter.Write (row.MinorVersion);
503                         m_binaryWriter.Write (row.BuildNumber);
504                         m_binaryWriter.Write (row.RevisionNumber);
505                         m_binaryWriter.Write ((uint) row.Flags);
506                         WriteBlobPointer (row.PublicKey);
507                         WriteStringPointer (row.Name);
508                         WriteStringPointer (row.Culture);
509                 }
510
511                 public override void VisitAssemblyOSRow (AssemblyOSRow row)
512                 {
513                         m_binaryWriter.Write (row.OSPlatformID);
514                         m_binaryWriter.Write (row.OSMajorVersion);
515                         m_binaryWriter.Write (row.OSMinorVersion);
516                 }
517
518                 public override void VisitAssemblyProcessorRow (AssemblyProcessorRow row)
519                 {
520                         m_binaryWriter.Write (row.Processor);
521                 }
522
523                 public override void VisitAssemblyRefRow (AssemblyRefRow row)
524                 {
525                         m_binaryWriter.Write (row.MajorVersion);
526                         m_binaryWriter.Write (row.MinorVersion);
527                         m_binaryWriter.Write (row.BuildNumber);
528                         m_binaryWriter.Write (row.RevisionNumber);
529                         m_binaryWriter.Write ((uint) row.Flags);
530                         WriteBlobPointer (row.PublicKeyOrToken);
531                         WriteStringPointer (row.Name);
532                         WriteStringPointer (row.Culture);
533                         WriteBlobPointer (row.HashValue);
534                 }
535
536                 public override void VisitAssemblyRefOSRow (AssemblyRefOSRow row)
537                 {
538                         m_binaryWriter.Write (row.OSPlatformID);
539                         m_binaryWriter.Write (row.OSMajorVersion);
540                         m_binaryWriter.Write (row.OSMinorVersion);
541                         WriteTablePointer (row.AssemblyRef, AssemblyRefTable.RId);
542                 }
543
544                 public override void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row)
545                 {
546                         m_binaryWriter.Write (row.Processor);
547                         WriteTablePointer (row.AssemblyRef, AssemblyRefTable.RId);
548                 }
549
550                 public override void VisitClassLayoutRow (ClassLayoutRow row)
551                 {
552                         m_binaryWriter.Write (row.PackingSize);
553                         m_binaryWriter.Write (row.ClassSize);
554                         WriteTablePointer (row.Parent, TypeDefTable.RId);
555                 }
556
557                 public override void VisitConstantRow (ConstantRow row)
558                 {
559                         m_binaryWriter.Write ((ushort) row.Type);
560                         WriteMetadataToken (row.Parent, CodedIndex.HasConstant);
561                         WriteBlobPointer (row.Value);
562                 }
563
564                 public override void VisitCustomAttributeRow (CustomAttributeRow row)
565                 {
566                         WriteMetadataToken (row.Parent, CodedIndex.HasCustomAttribute);
567                         WriteMetadataToken (row.Type, CodedIndex.CustomAttributeType);
568                         WriteBlobPointer (row.Value);
569                 }
570
571                 public override void VisitDeclSecurityRow (DeclSecurityRow row)
572                 {
573                         m_binaryWriter.Write ((short) row.Action);
574                         WriteMetadataToken (row.Parent, CodedIndex.HasDeclSecurity);
575                         WriteBlobPointer (row.PermissionSet);
576                 }
577
578                 public override void VisitEventRow (EventRow row)
579                 {
580                         m_binaryWriter.Write ((ushort) row.EventFlags);
581                         WriteStringPointer (row.Name);
582                         WriteMetadataToken (row.EventType, CodedIndex.TypeDefOrRef);
583                 }
584
585                 public override void VisitEventMapRow (EventMapRow row)
586                 {
587                         WriteTablePointer (row.Parent, TypeDefTable.RId);
588                         WriteTablePointer (row.EventList, EventTable.RId);
589                 }
590
591                 public override void VisitEventPtrRow (EventPtrRow row)
592                 {
593                         WriteTablePointer (row.Event, EventTable.RId);
594                 }
595
596                 public override void VisitExportedTypeRow (ExportedTypeRow row)
597                 {
598                         m_binaryWriter.Write ((uint) row.Flags);
599                         m_binaryWriter.Write (row.TypeDefId);
600                         WriteStringPointer (row.TypeName);
601                         WriteStringPointer (row.TypeNamespace);
602                         WriteMetadataToken (row.Implementation, CodedIndex.Implementation);
603                 }
604
605                 public override void VisitFieldRow (FieldRow row)
606                 {
607                         m_binaryWriter.Write ((ushort) row.Flags);
608                         WriteStringPointer (row.Name);
609                         WriteBlobPointer (row.Signature);
610                 }
611
612                 public override void VisitFieldLayoutRow (FieldLayoutRow row)
613                 {
614                         m_binaryWriter.Write (row.Offset);
615                         WriteTablePointer (row.Field, FieldTable.RId);
616                 }
617
618                 public override void VisitFieldMarshalRow (FieldMarshalRow row)
619                 {
620                         WriteMetadataToken (row.Parent, CodedIndex.HasFieldMarshal);
621                         WriteBlobPointer (row.NativeType);
622                 }
623
624                 public override void VisitFieldPtrRow (FieldPtrRow row)
625                 {
626                         WriteTablePointer (row.Field, FieldTable.RId);
627                 }
628
629                 public override void VisitFieldRVARow (FieldRVARow row)
630                 {
631                         m_binaryWriter.Write (row.RVA.Value);
632                         WriteTablePointer (row.Field, FieldTable.RId);
633                 }
634
635                 public override void VisitFileRow (FileRow row)
636                 {
637                         m_binaryWriter.Write ((uint) row.Flags);
638                         WriteStringPointer (row.Name);
639                         WriteBlobPointer (row.HashValue);
640                 }
641
642                 public override void VisitGenericParamRow (GenericParamRow row)
643                 {
644                         m_binaryWriter.Write (row.Number);
645                         m_binaryWriter.Write ((ushort) row.Flags);
646                         WriteMetadataToken (row.Owner, CodedIndex.TypeOrMethodDef);
647                         WriteStringPointer (row.Name);
648                 }
649
650                 public override void VisitGenericParamConstraintRow (GenericParamConstraintRow row)
651                 {
652                         WriteTablePointer (row.Owner, GenericParamTable.RId);
653                         WriteMetadataToken (row.Constraint, CodedIndex.TypeDefOrRef);
654                 }
655
656                 public override void VisitImplMapRow (ImplMapRow row)
657                 {
658                         m_binaryWriter.Write ((ushort) row.MappingFlags);
659                         WriteMetadataToken (row.MemberForwarded, CodedIndex.MemberForwarded);
660                         WriteStringPointer (row.ImportName);
661                         WriteTablePointer (row.ImportScope, ModuleRefTable.RId);
662                 }
663
664                 public override void VisitInterfaceImplRow (InterfaceImplRow row)
665                 {
666                         WriteTablePointer (row.Class, TypeDefTable.RId);
667                         WriteMetadataToken (row.Interface, CodedIndex.TypeDefOrRef);
668                 }
669
670                 public override void VisitManifestResourceRow (ManifestResourceRow row)
671                 {
672                         m_binaryWriter.Write (row.Offset);
673                         m_binaryWriter.Write ((uint) row.Flags);
674                         WriteStringPointer (row.Name);
675                         WriteMetadataToken (row.Implementation, CodedIndex.Implementation);
676                 }
677
678                 public override void VisitMemberRefRow (MemberRefRow row)
679                 {
680                         WriteMetadataToken (row.Class, CodedIndex.MemberRefParent);
681                         WriteStringPointer (row.Name);
682                         WriteBlobPointer (row.Signature);
683                 }
684
685                 public override void VisitMethodRow (MethodRow row)
686                 {
687                         m_binaryWriter.Write (row.RVA.Value);
688                         m_binaryWriter.Write ((ushort) row.ImplFlags);
689                         m_binaryWriter.Write ((ushort) row.Flags);
690                         WriteStringPointer (row.Name);
691                         WriteBlobPointer (row.Signature);
692                         WriteTablePointer (row.ParamList, ParamTable.RId);
693                 }
694
695                 public override void VisitMethodImplRow (MethodImplRow row)
696                 {
697                         WriteTablePointer (row.Class, TypeDefTable.RId);
698                         WriteMetadataToken (row.MethodBody, CodedIndex.MethodDefOrRef);
699                         WriteMetadataToken (row.MethodDeclaration, CodedIndex.MethodDefOrRef);
700                 }
701
702                 public override void VisitMethodPtrRow (MethodPtrRow row)
703                 {
704                         WriteTablePointer (row.Method, MethodTable.RId);
705                 }
706
707                 public override void VisitMethodSemanticsRow (MethodSemanticsRow row)
708                 {
709                         m_binaryWriter.Write ((ushort) row.Semantics);
710                         WriteTablePointer (row.Method, MethodTable.RId);
711                         WriteMetadataToken (row.Association, CodedIndex.HasSemantics);
712                 }
713
714                 public override void VisitMethodSpecRow (MethodSpecRow row)
715                 {
716                         WriteMetadataToken (row.Method, CodedIndex.MethodDefOrRef);
717                         WriteBlobPointer (row.Instantiation);
718                 }
719
720                 public override void VisitModuleRow (ModuleRow row)
721                 {
722                         m_binaryWriter.Write (row.Generation);
723                         WriteStringPointer (row.Name);
724                         WriteGuidPointer (row.Mvid);
725                         WriteGuidPointer (row.EncId);
726                         WriteGuidPointer (row.EncBaseId);
727                 }
728
729                 public override void VisitModuleRefRow (ModuleRefRow row)
730                 {
731                         WriteStringPointer (row.Name);
732                 }
733
734                 public override void VisitNestedClassRow (NestedClassRow row)
735                 {
736                         WriteTablePointer (row.NestedClass, TypeDefTable.RId);
737                         WriteTablePointer (row.EnclosingClass, TypeDefTable.RId);
738                 }
739
740                 public override void VisitParamRow (ParamRow row)
741                 {
742                         m_binaryWriter.Write ((ushort) row.Flags);
743                         m_binaryWriter.Write (row.Sequence);
744                         WriteStringPointer (row.Name);
745                 }
746
747                 public override void VisitParamPtrRow (ParamPtrRow row)
748                 {
749                         WriteTablePointer (row.Param, ParamTable.RId);
750                 }
751
752                 public override void VisitPropertyRow (PropertyRow row)
753                 {
754                         m_binaryWriter.Write ((ushort) row.Flags);
755                         WriteStringPointer (row.Name);
756                         WriteBlobPointer (row.Type);
757                 }
758
759                 public override void VisitPropertyMapRow (PropertyMapRow row)
760                 {
761                         WriteTablePointer (row.Parent, TypeDefTable.RId);
762                         WriteTablePointer (row.PropertyList, PropertyTable.RId);
763                 }
764
765                 public override void VisitPropertyPtrRow (PropertyPtrRow row)
766                 {
767                         WriteTablePointer (row.Property, PropertyTable.RId);
768                 }
769
770                 public override void VisitStandAloneSigRow (StandAloneSigRow row)
771                 {
772                         WriteBlobPointer (row.Signature);
773                 }
774
775                 public override void VisitTypeDefRow (TypeDefRow row)
776                 {
777                         m_binaryWriter.Write ((uint) row.Flags);
778                         WriteStringPointer (row.Name);
779                         WriteStringPointer (row.Namespace);
780                         WriteMetadataToken (row.Extends, CodedIndex.TypeDefOrRef);
781                         WriteTablePointer (row.FieldList, FieldTable.RId);
782                         WriteTablePointer (row.MethodList, MethodTable.RId);
783                 }
784
785                 public override void VisitTypeRefRow (TypeRefRow row)
786                 {
787                         WriteMetadataToken (row.ResolutionScope, CodedIndex.ResolutionScope);
788                         WriteStringPointer (row.Name);
789                         WriteStringPointer (row.Namespace);
790                 }
791
792                 public override void VisitTypeSpecRow (TypeSpecRow row)
793                 {
794                         WriteBlobPointer (row.Signature);
795                 }
796
797         }
798 }