| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.Collections.Immutable; |
| | | 6 | | using System.Diagnostics; |
| | | 7 | | using System.Reflection.Internal; |
| | | 8 | | |
| | | 9 | | namespace System.Reflection.Metadata.Ecma335 |
| | | 10 | | { |
| | | 11 | | public partial class MetadataBuilder |
| | | 12 | | { |
| | | 13 | | private const byte MetadataFormatMajorVersion = 2; |
| | | 14 | | private const byte MetadataFormatMinorVersion = 0; |
| | | 15 | | |
| | | 16 | | // type system table rows: |
| | | 17 | | private struct AssemblyRefTableRow { public Version Version; public BlobHandle PublicKeyToken; public StringHand |
| | | 18 | | private struct ModuleRow { public ushort Generation; public StringHandle Name; public GuidHandle ModuleVersionId |
| | | 19 | | private struct AssemblyRow { public uint HashAlgorithm; public Version Version; public ushort Flags; public Blob |
| | | 20 | | private struct ClassLayoutRow { public ushort PackingSize; public uint ClassSize; public int Parent; } |
| | | 21 | | private struct ConstantRow { public byte Type; public int Parent; public BlobHandle Value; } |
| | | 22 | | private struct CustomAttributeRow { public int Parent; public int Type; public BlobHandle Value; } |
| | | 23 | | private struct DeclSecurityRow { public ushort Action; public int Parent; public BlobHandle PermissionSet; } |
| | | 24 | | private struct EncLogRow { public int Token; public byte FuncCode; } |
| | | 25 | | private struct EncMapRow { public int Token; } |
| | | 26 | | private struct EventRow { public ushort EventFlags; public StringHandle Name; public int EventType; } |
| | | 27 | | private struct EventMapRow { public int Parent; public int EventList; } |
| | | 28 | | private struct ExportedTypeRow { public uint Flags; public int TypeDefId; public StringHandle TypeName; public S |
| | | 29 | | private struct FieldLayoutRow { public int Offset; public int Field; } |
| | | 30 | | private struct FieldMarshalRow { public int Parent; public BlobHandle NativeType; } |
| | | 31 | | private struct FieldRvaRow { public int Offset; public int Field; } |
| | | 32 | | private struct FieldDefRow { public ushort Flags; public StringHandle Name; public BlobHandle Signature; } |
| | | 33 | | private struct FileTableRow { public uint Flags; public StringHandle FileName; public BlobHandle HashValue; } |
| | | 34 | | private struct GenericParamConstraintRow { public int Owner; public int Constraint; } |
| | | 35 | | private struct GenericParamRow { public ushort Number; public ushort Flags; public int Owner; public StringHandl |
| | | 36 | | private struct ImplMapRow { public ushort MappingFlags; public int MemberForwarded; public StringHandle ImportNa |
| | | 37 | | private struct InterfaceImplRow { public int Class; public int Interface; } |
| | | 38 | | private struct ManifestResourceRow { public uint Offset; public uint Flags; public StringHandle Name; public int |
| | | 39 | | private struct MemberRefRow { public int Class; public StringHandle Name; public BlobHandle Signature; } |
| | | 40 | | private struct MethodImplRow { public int Class; public int MethodBody; public int MethodDecl; } |
| | | 41 | | private struct MethodSemanticsRow { public ushort Semantic; public int Method; public int Association; } |
| | | 42 | | private struct MethodSpecRow { public int Method; public BlobHandle Instantiation; } |
| | | 43 | | private struct MethodRow { public int BodyOffset; public ushort ImplFlags; public ushort Flags; public StringHan |
| | | 44 | | private struct ModuleRefRow { public StringHandle Name; } |
| | | 45 | | private struct NestedClassRow { public int NestedClass; public int EnclosingClass; } |
| | | 46 | | private struct ParamRow { public ushort Flags; public ushort Sequence; public StringHandle Name; } |
| | | 47 | | private struct PropertyMapRow { public int Parent; public int PropertyList; } |
| | | 48 | | private struct PropertyRow { public ushort PropFlags; public StringHandle Name; public BlobHandle Type; } |
| | | 49 | | private struct TypeDefRow { public uint Flags; public StringHandle Name; public StringHandle Namespace; public i |
| | | 50 | | private struct TypeRefRow { public int ResolutionScope; public StringHandle Name; public StringHandle Namespace; |
| | | 51 | | private struct TypeSpecRow { public BlobHandle Signature; } |
| | | 52 | | private struct StandaloneSigRow { public BlobHandle Signature; } |
| | | 53 | | |
| | | 54 | | // debug table rows: |
| | | 55 | | private struct DocumentRow { public BlobHandle Name; public GuidHandle HashAlgorithm; public BlobHandle Hash; pu |
| | | 56 | | private struct MethodDebugInformationRow { public int Document; public BlobHandle SequencePoints; } |
| | | 57 | | private struct LocalScopeRow { public int Method; public int ImportScope; public int VariableList; public int Co |
| | | 58 | | private struct LocalVariableRow { public ushort Attributes; public ushort Index; public StringHandle Name; } |
| | | 59 | | private struct LocalConstantRow { public StringHandle Name; public BlobHandle Signature; } |
| | | 60 | | private struct ImportScopeRow { public int Parent; public BlobHandle Imports; } |
| | | 61 | | private struct StateMachineMethodRow { public int MoveNextMethod; public int KickoffMethod; } |
| | | 62 | | private struct CustomDebugInformationRow { public int Parent; public GuidHandle Kind; public BlobHandle Value; } |
| | | 63 | | |
| | | 64 | | // type system tables: |
| | | 65 | | private ModuleRow? _moduleRow; |
| | | 66 | | private AssemblyRow? _assemblyRow; |
| | 0 | 67 | | private readonly List<ClassLayoutRow> _classLayoutTable = new List<ClassLayoutRow>(); |
| | | 68 | | |
| | 0 | 69 | | private readonly List<ConstantRow> _constantTable = new List<ConstantRow>(); |
| | | 70 | | private int _constantTableLastParent; |
| | | 71 | | private bool _constantTableNeedsSorting; |
| | | 72 | | |
| | 0 | 73 | | private readonly List<CustomAttributeRow> _customAttributeTable = new List<CustomAttributeRow>(); |
| | | 74 | | private int _customAttributeTableLastParent; |
| | | 75 | | private bool _customAttributeTableNeedsSorting; |
| | | 76 | | |
| | 0 | 77 | | private readonly List<DeclSecurityRow> _declSecurityTable = new List<DeclSecurityRow>(); |
| | | 78 | | private int _declSecurityTableLastParent; |
| | | 79 | | private bool _declSecurityTableNeedsSorting; |
| | | 80 | | |
| | 0 | 81 | | private readonly List<EncLogRow> _encLogTable = new List<EncLogRow>(); |
| | 0 | 82 | | private readonly List<EncMapRow> _encMapTable = new List<EncMapRow>(); |
| | 0 | 83 | | private readonly List<EventRow> _eventTable = new List<EventRow>(); |
| | 0 | 84 | | private readonly List<EventMapRow> _eventMapTable = new List<EventMapRow>(); |
| | 0 | 85 | | private readonly List<ExportedTypeRow> _exportedTypeTable = new List<ExportedTypeRow>(); |
| | 0 | 86 | | private readonly List<FieldLayoutRow> _fieldLayoutTable = new List<FieldLayoutRow>(); |
| | | 87 | | |
| | 0 | 88 | | private readonly List<FieldMarshalRow> _fieldMarshalTable = new List<FieldMarshalRow>(); |
| | | 89 | | private int _fieldMarshalTableLastParent; |
| | | 90 | | private bool _fieldMarshalTableNeedsSorting; |
| | | 91 | | |
| | 0 | 92 | | private readonly List<FieldRvaRow> _fieldRvaTable = new List<FieldRvaRow>(); |
| | 0 | 93 | | private readonly List<FieldDefRow> _fieldTable = new List<FieldDefRow>(); |
| | 0 | 94 | | private readonly List<FileTableRow> _fileTable = new List<FileTableRow>(); |
| | 0 | 95 | | private readonly List<GenericParamConstraintRow> _genericParamConstraintTable = new List<GenericParamConstraintR |
| | 0 | 96 | | private readonly List<GenericParamRow> _genericParamTable = new List<GenericParamRow>(); |
| | 0 | 97 | | private readonly List<ImplMapRow> _implMapTable = new List<ImplMapRow>(); |
| | 0 | 98 | | private readonly List<InterfaceImplRow> _interfaceImplTable = new List<InterfaceImplRow>(); |
| | 0 | 99 | | private readonly List<ManifestResourceRow> _manifestResourceTable = new List<ManifestResourceRow>(); |
| | 0 | 100 | | private readonly List<MemberRefRow> _memberRefTable = new List<MemberRefRow>(); |
| | 0 | 101 | | private readonly List<MethodImplRow> _methodImplTable = new List<MethodImplRow>(); |
| | | 102 | | |
| | 0 | 103 | | private readonly List<MethodSemanticsRow> _methodSemanticsTable = new List<MethodSemanticsRow>(); |
| | | 104 | | private int _methodSemanticsTableLastAssociation; |
| | | 105 | | private bool _methodSemanticsTableNeedsSorting; |
| | | 106 | | |
| | 0 | 107 | | private readonly List<MethodSpecRow> _methodSpecTable = new List<MethodSpecRow>(); |
| | 0 | 108 | | private readonly List<MethodRow> _methodDefTable = new List<MethodRow>(); |
| | 0 | 109 | | private readonly List<ModuleRefRow> _moduleRefTable = new List<ModuleRefRow>(); |
| | 0 | 110 | | private readonly List<NestedClassRow> _nestedClassTable = new List<NestedClassRow>(); |
| | 0 | 111 | | private readonly List<ParamRow> _paramTable = new List<ParamRow>(); |
| | 0 | 112 | | private readonly List<PropertyMapRow> _propertyMapTable = new List<PropertyMapRow>(); |
| | 0 | 113 | | private readonly List<PropertyRow> _propertyTable = new List<PropertyRow>(); |
| | 0 | 114 | | private readonly List<TypeDefRow> _typeDefTable = new List<TypeDefRow>(); |
| | 0 | 115 | | private readonly List<TypeRefRow> _typeRefTable = new List<TypeRefRow>(); |
| | 0 | 116 | | private readonly List<TypeSpecRow> _typeSpecTable = new List<TypeSpecRow>(); |
| | 0 | 117 | | private readonly List<AssemblyRefTableRow> _assemblyRefTable = new List<AssemblyRefTableRow>(); |
| | 0 | 118 | | private readonly List<StandaloneSigRow> _standAloneSigTable = new List<StandaloneSigRow>(); |
| | | 119 | | |
| | | 120 | | // debug tables: |
| | 0 | 121 | | private readonly List<DocumentRow> _documentTable = new List<DocumentRow>(); |
| | 0 | 122 | | private readonly List<MethodDebugInformationRow> _methodDebugInformationTable = new List<MethodDebugInformationR |
| | 0 | 123 | | private readonly List<LocalScopeRow> _localScopeTable = new List<LocalScopeRow>(); |
| | 0 | 124 | | private readonly List<LocalVariableRow> _localVariableTable = new List<LocalVariableRow>(); |
| | 0 | 125 | | private readonly List<LocalConstantRow> _localConstantTable = new List<LocalConstantRow>(); |
| | 0 | 126 | | private readonly List<ImportScopeRow> _importScopeTable = new List<ImportScopeRow>(); |
| | 0 | 127 | | private readonly List<StateMachineMethodRow> _stateMachineMethodTable = new List<StateMachineMethodRow>(); |
| | 0 | 128 | | private readonly List<CustomDebugInformationRow> _customDebugInformationTable = new List<CustomDebugInformationR |
| | | 129 | | |
| | | 130 | | /// <summary> |
| | | 131 | | /// Sets the capacity of the specified table. |
| | | 132 | | /// </summary> |
| | | 133 | | /// <exception cref="ArgumentOutOfRangeException"><paramref name="table"/> is not a valid table index.</exceptio |
| | | 134 | | /// <exception cref="ArgumentOutOfRangeException"><paramref name="rowCount"/> is negative.</exception> |
| | | 135 | | /// <remarks> |
| | | 136 | | /// Use to reduce allocations if the approximate number of rows is known ahead of time. |
| | | 137 | | /// </remarks> |
| | | 138 | | public void SetCapacity(TableIndex table, int rowCount) |
| | 0 | 139 | | { |
| | 0 | 140 | | if (rowCount < 0) |
| | 0 | 141 | | { |
| | 0 | 142 | | Throw.ArgumentOutOfRange(nameof(rowCount)); |
| | | 143 | | } |
| | | 144 | | |
| | 0 | 145 | | switch (table) |
| | | 146 | | { |
| | 0 | 147 | | case TableIndex.Module: break; // no-op, max row count is 1 |
| | 0 | 148 | | case TableIndex.TypeRef: SetTableCapacity(_typeRefTable, rowCount); break; |
| | 0 | 149 | | case TableIndex.TypeDef: SetTableCapacity(_typeDefTable, rowCount); break; |
| | 0 | 150 | | case TableIndex.Field: SetTableCapacity(_fieldTable, rowCount); break; |
| | 0 | 151 | | case TableIndex.MethodDef: SetTableCapacity(_methodDefTable, rowCount); break; |
| | 0 | 152 | | case TableIndex.Param: SetTableCapacity(_paramTable, rowCount); break; |
| | 0 | 153 | | case TableIndex.InterfaceImpl: SetTableCapacity(_interfaceImplTable, rowCount); break; |
| | 0 | 154 | | case TableIndex.MemberRef: SetTableCapacity(_memberRefTable, rowCount); break; |
| | 0 | 155 | | case TableIndex.Constant: SetTableCapacity(_constantTable, rowCount); break; |
| | 0 | 156 | | case TableIndex.CustomAttribute: SetTableCapacity(_customAttributeTable, rowCount); break; |
| | 0 | 157 | | case TableIndex.FieldMarshal: SetTableCapacity(_fieldMarshalTable, rowCount); break; |
| | 0 | 158 | | case TableIndex.DeclSecurity: SetTableCapacity(_declSecurityTable, rowCount); break; |
| | 0 | 159 | | case TableIndex.ClassLayout: SetTableCapacity(_classLayoutTable, rowCount); break; |
| | 0 | 160 | | case TableIndex.FieldLayout: SetTableCapacity(_fieldLayoutTable, rowCount); break; |
| | 0 | 161 | | case TableIndex.StandAloneSig: SetTableCapacity(_standAloneSigTable, rowCount); break; |
| | 0 | 162 | | case TableIndex.EventMap: SetTableCapacity(_eventMapTable, rowCount); break; |
| | 0 | 163 | | case TableIndex.Event: SetTableCapacity(_eventTable, rowCount); break; |
| | 0 | 164 | | case TableIndex.PropertyMap: SetTableCapacity(_propertyMapTable, rowCount); break; |
| | 0 | 165 | | case TableIndex.Property: SetTableCapacity(_propertyTable, rowCount); break; |
| | 0 | 166 | | case TableIndex.MethodSemantics: SetTableCapacity(_methodSemanticsTable, rowCount); break; |
| | 0 | 167 | | case TableIndex.MethodImpl: SetTableCapacity(_methodImplTable, rowCount); break; |
| | 0 | 168 | | case TableIndex.ModuleRef: SetTableCapacity(_moduleRefTable, rowCount); break; |
| | 0 | 169 | | case TableIndex.TypeSpec: SetTableCapacity(_typeSpecTable, rowCount); break; |
| | 0 | 170 | | case TableIndex.ImplMap: SetTableCapacity(_implMapTable, rowCount); break; |
| | 0 | 171 | | case TableIndex.FieldRva: SetTableCapacity(_fieldRvaTable, rowCount); break; |
| | 0 | 172 | | case TableIndex.EncLog: SetTableCapacity(_encLogTable, rowCount); break; |
| | 0 | 173 | | case TableIndex.EncMap: SetTableCapacity(_encMapTable, rowCount); break; |
| | 0 | 174 | | case TableIndex.Assembly: break; // no-op, max row count is 1 |
| | 0 | 175 | | case TableIndex.AssemblyRef: SetTableCapacity(_assemblyRefTable, rowCount); break; |
| | 0 | 176 | | case TableIndex.File: SetTableCapacity(_fileTable, rowCount); break; |
| | 0 | 177 | | case TableIndex.ExportedType: SetTableCapacity(_exportedTypeTable, rowCount); break; |
| | 0 | 178 | | case TableIndex.ManifestResource: SetTableCapacity(_manifestResourceTable, rowCount); break; |
| | 0 | 179 | | case TableIndex.NestedClass: SetTableCapacity(_nestedClassTable, rowCount); break; |
| | 0 | 180 | | case TableIndex.GenericParam: SetTableCapacity(_genericParamTable, rowCount); break; |
| | 0 | 181 | | case TableIndex.MethodSpec: SetTableCapacity(_methodSpecTable, rowCount); break; |
| | 0 | 182 | | case TableIndex.GenericParamConstraint: SetTableCapacity(_genericParamConstraintTable, rowCount); break; |
| | 0 | 183 | | case TableIndex.Document: SetTableCapacity(_documentTable, rowCount); break; |
| | 0 | 184 | | case TableIndex.MethodDebugInformation: SetTableCapacity(_methodDebugInformationTable, rowCount); break; |
| | 0 | 185 | | case TableIndex.LocalScope: SetTableCapacity(_localScopeTable, rowCount); break; |
| | 0 | 186 | | case TableIndex.LocalVariable: SetTableCapacity(_localVariableTable, rowCount); break; |
| | 0 | 187 | | case TableIndex.LocalConstant: SetTableCapacity(_localConstantTable, rowCount); break; |
| | 0 | 188 | | case TableIndex.ImportScope: SetTableCapacity(_importScopeTable, rowCount); break; |
| | 0 | 189 | | case TableIndex.StateMachineMethod: SetTableCapacity(_stateMachineMethodTable, rowCount); break; |
| | 0 | 190 | | case TableIndex.CustomDebugInformation: SetTableCapacity(_customDebugInformationTable, rowCount); break; |
| | | 191 | | |
| | | 192 | | case TableIndex.AssemblyOS: |
| | | 193 | | case TableIndex.AssemblyProcessor: |
| | | 194 | | case TableIndex.AssemblyRefOS: |
| | | 195 | | case TableIndex.AssemblyRefProcessor: |
| | | 196 | | case TableIndex.EventPtr: |
| | | 197 | | case TableIndex.FieldPtr: |
| | | 198 | | case TableIndex.MethodPtr: |
| | | 199 | | case TableIndex.ParamPtr: |
| | | 200 | | case TableIndex.PropertyPtr: |
| | | 201 | | // these tables are currently not serialized |
| | 0 | 202 | | break; |
| | | 203 | | |
| | | 204 | | default: |
| | 0 | 205 | | throw new ArgumentOutOfRangeException(nameof(table)); |
| | | 206 | | } |
| | 0 | 207 | | } |
| | | 208 | | |
| | | 209 | | private static void SetTableCapacity<T>(List<T> table, int rowCount) |
| | 0 | 210 | | { |
| | 0 | 211 | | if (rowCount > table.Count) |
| | 0 | 212 | | { |
| | 0 | 213 | | table.Capacity = rowCount; |
| | 0 | 214 | | } |
| | 0 | 215 | | } |
| | | 216 | | |
| | | 217 | | /// <summary> |
| | | 218 | | /// Returns the current number of entries in the specified table. |
| | | 219 | | /// </summary> |
| | | 220 | | /// <param name="table">Table index.</param> |
| | | 221 | | /// <returns>The number of entries in the table.</returns> |
| | | 222 | | /// <exception cref="ArgumentOutOfRangeException"><paramref name="table"/> is not a valid table index.</exceptio |
| | | 223 | | public int GetRowCount(TableIndex table) |
| | 0 | 224 | | { |
| | 0 | 225 | | switch (table) |
| | | 226 | | { |
| | 0 | 227 | | case TableIndex.Assembly : return _assemblyRow.HasValue ? 1 : 0; |
| | 0 | 228 | | case TableIndex.AssemblyRef : return _assemblyRefTable.Count; |
| | 0 | 229 | | case TableIndex.ClassLayout : return _classLayoutTable.Count; |
| | 0 | 230 | | case TableIndex.Constant : return _constantTable.Count; |
| | 0 | 231 | | case TableIndex.CustomAttribute : return _customAttributeTable.Count; |
| | 0 | 232 | | case TableIndex.DeclSecurity : return _declSecurityTable.Count; |
| | 0 | 233 | | case TableIndex.EncLog : return _encLogTable.Count; |
| | 0 | 234 | | case TableIndex.EncMap : return _encMapTable.Count; |
| | 0 | 235 | | case TableIndex.EventMap : return _eventMapTable.Count; |
| | 0 | 236 | | case TableIndex.Event : return _eventTable.Count; |
| | 0 | 237 | | case TableIndex.ExportedType : return _exportedTypeTable.Count; |
| | 0 | 238 | | case TableIndex.FieldLayout : return _fieldLayoutTable.Count; |
| | 0 | 239 | | case TableIndex.FieldMarshal : return _fieldMarshalTable.Count; |
| | 0 | 240 | | case TableIndex.FieldRva : return _fieldRvaTable.Count; |
| | 0 | 241 | | case TableIndex.Field : return _fieldTable.Count; |
| | 0 | 242 | | case TableIndex.File : return _fileTable.Count; |
| | 0 | 243 | | case TableIndex.GenericParamConstraint : return _genericParamConstraintTable.Count; |
| | 0 | 244 | | case TableIndex.GenericParam : return _genericParamTable.Count; |
| | 0 | 245 | | case TableIndex.ImplMap : return _implMapTable.Count; |
| | 0 | 246 | | case TableIndex.InterfaceImpl : return _interfaceImplTable.Count; |
| | 0 | 247 | | case TableIndex.ManifestResource : return _manifestResourceTable.Count; |
| | 0 | 248 | | case TableIndex.MemberRef : return _memberRefTable.Count; |
| | 0 | 249 | | case TableIndex.MethodImpl : return _methodImplTable.Count; |
| | 0 | 250 | | case TableIndex.MethodSemantics : return _methodSemanticsTable.Count; |
| | 0 | 251 | | case TableIndex.MethodSpec : return _methodSpecTable.Count; |
| | 0 | 252 | | case TableIndex.MethodDef : return _methodDefTable.Count; |
| | 0 | 253 | | case TableIndex.ModuleRef : return _moduleRefTable.Count; |
| | 0 | 254 | | case TableIndex.Module : return _moduleRow.HasValue ? 1 : 0; |
| | 0 | 255 | | case TableIndex.NestedClass : return _nestedClassTable.Count; |
| | 0 | 256 | | case TableIndex.Param : return _paramTable.Count; |
| | 0 | 257 | | case TableIndex.PropertyMap : return _propertyMapTable.Count; |
| | 0 | 258 | | case TableIndex.Property : return _propertyTable.Count; |
| | 0 | 259 | | case TableIndex.StandAloneSig : return _standAloneSigTable.Count; |
| | 0 | 260 | | case TableIndex.TypeDef : return _typeDefTable.Count; |
| | 0 | 261 | | case TableIndex.TypeRef : return _typeRefTable.Count; |
| | 0 | 262 | | case TableIndex.TypeSpec : return _typeSpecTable.Count; |
| | 0 | 263 | | case TableIndex.Document : return _documentTable.Count; |
| | 0 | 264 | | case TableIndex.MethodDebugInformation : return _methodDebugInformationTable.Count; |
| | 0 | 265 | | case TableIndex.LocalScope : return _localScopeTable.Count; |
| | 0 | 266 | | case TableIndex.LocalVariable : return _localVariableTable.Count; |
| | 0 | 267 | | case TableIndex.LocalConstant : return _localConstantTable.Count; |
| | 0 | 268 | | case TableIndex.StateMachineMethod : return _stateMachineMethodTable.Count; |
| | 0 | 269 | | case TableIndex.ImportScope : return _importScopeTable.Count; |
| | 0 | 270 | | case TableIndex.CustomDebugInformation : return _customDebugInformationTable.Count; |
| | | 271 | | |
| | | 272 | | case TableIndex.AssemblyOS: |
| | | 273 | | case TableIndex.AssemblyProcessor: |
| | | 274 | | case TableIndex.AssemblyRefOS: |
| | | 275 | | case TableIndex.AssemblyRefProcessor: |
| | | 276 | | case TableIndex.EventPtr: |
| | | 277 | | case TableIndex.FieldPtr: |
| | | 278 | | case TableIndex.MethodPtr: |
| | | 279 | | case TableIndex.ParamPtr: |
| | | 280 | | case TableIndex.PropertyPtr: |
| | 0 | 281 | | return 0; |
| | | 282 | | |
| | | 283 | | default: |
| | 0 | 284 | | throw new ArgumentOutOfRangeException(nameof(table)); |
| | | 285 | | } |
| | 0 | 286 | | } |
| | | 287 | | |
| | | 288 | | /// <summary> |
| | | 289 | | /// Returns the current number of entries in each table. |
| | | 290 | | /// </summary> |
| | | 291 | | /// <returns> |
| | | 292 | | /// An array of size <see cref="MetadataTokens.TableCount"/> with each item filled with the current row count of |
| | | 293 | | /// </returns> |
| | | 294 | | public ImmutableArray<int> GetRowCounts() |
| | 0 | 295 | | { |
| | 0 | 296 | | var rowCounts = ImmutableArray.CreateBuilder<int>(MetadataTokens.TableCount); |
| | 0 | 297 | | rowCounts.Count = MetadataTokens.TableCount; |
| | | 298 | | |
| | 0 | 299 | | rowCounts[(int)TableIndex.Assembly] = _assemblyRow.HasValue ? 1 : 0; |
| | 0 | 300 | | rowCounts[(int)TableIndex.AssemblyRef] = _assemblyRefTable.Count; |
| | 0 | 301 | | rowCounts[(int)TableIndex.ClassLayout] = _classLayoutTable.Count; |
| | 0 | 302 | | rowCounts[(int)TableIndex.Constant] = _constantTable.Count; |
| | 0 | 303 | | rowCounts[(int)TableIndex.CustomAttribute] = _customAttributeTable.Count; |
| | 0 | 304 | | rowCounts[(int)TableIndex.DeclSecurity] = _declSecurityTable.Count; |
| | 0 | 305 | | rowCounts[(int)TableIndex.EncLog] = _encLogTable.Count; |
| | 0 | 306 | | rowCounts[(int)TableIndex.EncMap] = _encMapTable.Count; |
| | 0 | 307 | | rowCounts[(int)TableIndex.EventMap] = _eventMapTable.Count; |
| | 0 | 308 | | rowCounts[(int)TableIndex.Event] = _eventTable.Count; |
| | 0 | 309 | | rowCounts[(int)TableIndex.ExportedType] = _exportedTypeTable.Count; |
| | 0 | 310 | | rowCounts[(int)TableIndex.FieldLayout] = _fieldLayoutTable.Count; |
| | 0 | 311 | | rowCounts[(int)TableIndex.FieldMarshal] = _fieldMarshalTable.Count; |
| | 0 | 312 | | rowCounts[(int)TableIndex.FieldRva] = _fieldRvaTable.Count; |
| | 0 | 313 | | rowCounts[(int)TableIndex.Field] = _fieldTable.Count; |
| | 0 | 314 | | rowCounts[(int)TableIndex.File] = _fileTable.Count; |
| | 0 | 315 | | rowCounts[(int)TableIndex.GenericParamConstraint] = _genericParamConstraintTable.Count; |
| | 0 | 316 | | rowCounts[(int)TableIndex.GenericParam] = _genericParamTable.Count; |
| | 0 | 317 | | rowCounts[(int)TableIndex.ImplMap] = _implMapTable.Count; |
| | 0 | 318 | | rowCounts[(int)TableIndex.InterfaceImpl] = _interfaceImplTable.Count; |
| | 0 | 319 | | rowCounts[(int)TableIndex.ManifestResource] = _manifestResourceTable.Count; |
| | 0 | 320 | | rowCounts[(int)TableIndex.MemberRef] = _memberRefTable.Count; |
| | 0 | 321 | | rowCounts[(int)TableIndex.MethodImpl] = _methodImplTable.Count; |
| | 0 | 322 | | rowCounts[(int)TableIndex.MethodSemantics] = _methodSemanticsTable.Count; |
| | 0 | 323 | | rowCounts[(int)TableIndex.MethodSpec] = _methodSpecTable.Count; |
| | 0 | 324 | | rowCounts[(int)TableIndex.MethodDef] = _methodDefTable.Count; |
| | 0 | 325 | | rowCounts[(int)TableIndex.ModuleRef] = _moduleRefTable.Count; |
| | 0 | 326 | | rowCounts[(int)TableIndex.Module] = _moduleRow.HasValue ? 1 : 0; |
| | 0 | 327 | | rowCounts[(int)TableIndex.NestedClass] = _nestedClassTable.Count; |
| | 0 | 328 | | rowCounts[(int)TableIndex.Param] = _paramTable.Count; |
| | 0 | 329 | | rowCounts[(int)TableIndex.PropertyMap] = _propertyMapTable.Count; |
| | 0 | 330 | | rowCounts[(int)TableIndex.Property] = _propertyTable.Count; |
| | 0 | 331 | | rowCounts[(int)TableIndex.StandAloneSig] = _standAloneSigTable.Count; |
| | 0 | 332 | | rowCounts[(int)TableIndex.TypeDef] = _typeDefTable.Count; |
| | 0 | 333 | | rowCounts[(int)TableIndex.TypeRef] = _typeRefTable.Count; |
| | 0 | 334 | | rowCounts[(int)TableIndex.TypeSpec] = _typeSpecTable.Count; |
| | | 335 | | |
| | 0 | 336 | | rowCounts[(int)TableIndex.Document] = _documentTable.Count; |
| | 0 | 337 | | rowCounts[(int)TableIndex.MethodDebugInformation] = _methodDebugInformationTable.Count; |
| | 0 | 338 | | rowCounts[(int)TableIndex.LocalScope] = _localScopeTable.Count; |
| | 0 | 339 | | rowCounts[(int)TableIndex.LocalVariable] = _localVariableTable.Count; |
| | 0 | 340 | | rowCounts[(int)TableIndex.LocalConstant] = _localConstantTable.Count; |
| | 0 | 341 | | rowCounts[(int)TableIndex.StateMachineMethod] = _stateMachineMethodTable.Count; |
| | 0 | 342 | | rowCounts[(int)TableIndex.ImportScope] = _importScopeTable.Count; |
| | 0 | 343 | | rowCounts[(int)TableIndex.CustomDebugInformation] = _customDebugInformationTable.Count; |
| | | 344 | | |
| | 0 | 345 | | return rowCounts.MoveToImmutable(); |
| | 0 | 346 | | } |
| | | 347 | | |
| | | 348 | | #region Building |
| | | 349 | | |
| | | 350 | | // Note on argument value checking: |
| | | 351 | | // |
| | | 352 | | // To avoid perf overhead we do minimal argument checking. |
| | | 353 | | // We only check integer parameter bounds if we perform a narrowing conversion, |
| | | 354 | | // so that we don't mangle values that match the Add method signature but are too big to represent in the metada |
| | | 355 | | // We do not validate ranges of enum values, we just ignore high bits when converting to smaller integral type. |
| | | 356 | | // Adding such checks would unlikely catch bugs in reasonably written code. |
| | | 357 | | |
| | | 358 | | public ModuleDefinitionHandle AddModule( |
| | | 359 | | int generation, |
| | | 360 | | StringHandle moduleName, |
| | | 361 | | GuidHandle mvid, |
| | | 362 | | GuidHandle encId, |
| | | 363 | | GuidHandle encBaseId) |
| | 0 | 364 | | { |
| | 0 | 365 | | if (unchecked((uint)generation) > ushort.MaxValue) |
| | 0 | 366 | | { |
| | 0 | 367 | | Throw.ArgumentOutOfRange(nameof(generation)); |
| | | 368 | | } |
| | | 369 | | |
| | 0 | 370 | | if (_moduleRow.HasValue) |
| | 0 | 371 | | { |
| | 0 | 372 | | Throw.InvalidOperation(SR.ModuleAlreadyAdded); |
| | | 373 | | } |
| | | 374 | | |
| | 0 | 375 | | _moduleRow = new ModuleRow |
| | 0 | 376 | | { |
| | 0 | 377 | | Generation = (ushort)generation, |
| | 0 | 378 | | Name = moduleName, |
| | 0 | 379 | | ModuleVersionId = mvid, |
| | 0 | 380 | | EncId = encId, |
| | 0 | 381 | | EncBaseId = encBaseId, |
| | 0 | 382 | | }; |
| | | 383 | | |
| | 0 | 384 | | return EntityHandle.ModuleDefinition; |
| | 0 | 385 | | } |
| | | 386 | | |
| | | 387 | | public AssemblyDefinitionHandle AddAssembly( |
| | | 388 | | StringHandle name, |
| | | 389 | | Version version, |
| | | 390 | | StringHandle culture, |
| | | 391 | | BlobHandle publicKey, |
| | | 392 | | AssemblyFlags flags, |
| | | 393 | | AssemblyHashAlgorithm hashAlgorithm) |
| | 0 | 394 | | { |
| | 0 | 395 | | if (version is null) |
| | 0 | 396 | | { |
| | 0 | 397 | | Throw.ArgumentNull(nameof(version)); |
| | | 398 | | } |
| | | 399 | | |
| | 0 | 400 | | if (_assemblyRow.HasValue) |
| | 0 | 401 | | { |
| | 0 | 402 | | Throw.InvalidOperation(SR.AssemblyAlreadyAdded); |
| | | 403 | | } |
| | | 404 | | |
| | 0 | 405 | | _assemblyRow = new AssemblyRow |
| | 0 | 406 | | { |
| | 0 | 407 | | Flags = unchecked((ushort)flags), |
| | 0 | 408 | | HashAlgorithm = unchecked((uint)hashAlgorithm), |
| | 0 | 409 | | Version = version, |
| | 0 | 410 | | AssemblyKey = publicKey, |
| | 0 | 411 | | AssemblyName = name, |
| | 0 | 412 | | AssemblyCulture = culture |
| | 0 | 413 | | }; |
| | | 414 | | |
| | 0 | 415 | | return EntityHandle.AssemblyDefinition; |
| | 0 | 416 | | } |
| | | 417 | | |
| | | 418 | | public AssemblyReferenceHandle AddAssemblyReference( |
| | | 419 | | StringHandle name, |
| | | 420 | | Version version, |
| | | 421 | | StringHandle culture, |
| | | 422 | | BlobHandle publicKeyOrToken, |
| | | 423 | | AssemblyFlags flags, |
| | | 424 | | BlobHandle hashValue) |
| | 0 | 425 | | { |
| | 0 | 426 | | if (version is null) |
| | 0 | 427 | | { |
| | 0 | 428 | | Throw.ArgumentNull(nameof(version)); |
| | | 429 | | } |
| | | 430 | | |
| | 0 | 431 | | _assemblyRefTable.Add(new AssemblyRefTableRow |
| | 0 | 432 | | { |
| | 0 | 433 | | Name = name, |
| | 0 | 434 | | Version = version, |
| | 0 | 435 | | Culture = culture, |
| | 0 | 436 | | PublicKeyToken = publicKeyOrToken, |
| | 0 | 437 | | Flags = unchecked((uint)flags), |
| | 0 | 438 | | HashValue = hashValue |
| | 0 | 439 | | }); |
| | | 440 | | |
| | 0 | 441 | | return AssemblyReferenceHandle.FromRowId(_assemblyRefTable.Count); |
| | 0 | 442 | | } |
| | | 443 | | |
| | | 444 | | /// <summary> |
| | | 445 | | /// Adds a type definition. |
| | | 446 | | /// </summary> |
| | | 447 | | /// <param name="attributes">Attributes</param> |
| | | 448 | | /// <param name="namespace">Namespace</param> |
| | | 449 | | /// <param name="name">Type name</param> |
| | | 450 | | /// <param name="baseType"><see cref="TypeDefinitionHandle"/>, <see cref="TypeReferenceHandle"/>, <see cref="Typ |
| | | 451 | | /// <param name="fieldList"> |
| | | 452 | | /// If the type declares fields the handle of the first one, otherwise the handle of the first field declared by |
| | | 453 | | /// If no type defines any fields in the module, <see cref="MetadataTokens.FieldDefinitionHandle(int)"/>(1). |
| | | 454 | | /// </param> |
| | | 455 | | /// <param name="methodList"> |
| | | 456 | | /// If the type declares methods the handle of the first one, otherwise the handle of the first method declared |
| | | 457 | | /// If no type defines any methods in the module, <see cref="MetadataTokens.MethodDefinitionHandle(int)"/>(1). |
| | | 458 | | /// </param> |
| | | 459 | | /// <exception cref="ArgumentException"><paramref name="baseType"/> doesn't have the expected handle kind.</exce |
| | | 460 | | public TypeDefinitionHandle AddTypeDefinition( |
| | | 461 | | TypeAttributes attributes, |
| | | 462 | | StringHandle @namespace, |
| | | 463 | | StringHandle name, |
| | | 464 | | EntityHandle baseType, |
| | | 465 | | FieldDefinitionHandle fieldList, |
| | | 466 | | MethodDefinitionHandle methodList) |
| | 0 | 467 | | { |
| | 0 | 468 | | _typeDefTable.Add(new TypeDefRow |
| | 0 | 469 | | { |
| | 0 | 470 | | Flags = unchecked((uint)attributes), |
| | 0 | 471 | | Name = name, |
| | 0 | 472 | | Namespace = @namespace, |
| | 0 | 473 | | Extends = baseType.IsNil ? 0 : CodedIndex.TypeDefOrRefOrSpec(baseType), |
| | 0 | 474 | | FieldList = fieldList.RowId, |
| | 0 | 475 | | MethodList = methodList.RowId |
| | 0 | 476 | | }); |
| | | 477 | | |
| | 0 | 478 | | return TypeDefinitionHandle.FromRowId(_typeDefTable.Count); |
| | 0 | 479 | | } |
| | | 480 | | |
| | | 481 | | /// <summary> |
| | | 482 | | /// Defines a type layout of a type definition. |
| | | 483 | | /// </summary> |
| | | 484 | | /// <param name="type">Type definition.</param> |
| | | 485 | | /// <param name="packingSize"> |
| | | 486 | | /// Specifies that fields should be placed within the type instance at byte addresses which are a multiple of th |
| | | 487 | | /// or at natural alignment for that field type, whichever is smaller. Shall be one of the following: 0, 1, 2, 4 |
| | | 488 | | /// A value of zero indicates that the packing size used should match the default for the current platform. |
| | | 489 | | /// </param> |
| | | 490 | | /// <param name="size"> |
| | | 491 | | /// Indicates a minimum size of the type instance, and is intended to allow for padding. |
| | | 492 | | /// The amount of memory allocated is the maximum of the size calculated from the layout and <paramref name="siz |
| | | 493 | | /// Note that if this directive applies to a value type, then the size shall be less than 1 MB. |
| | | 494 | | /// </param> |
| | | 495 | | /// <remarks> |
| | | 496 | | /// Entries must be added in the same order as the corresponding type definitions. |
| | | 497 | | /// </remarks> |
| | | 498 | | public void AddTypeLayout( |
| | | 499 | | TypeDefinitionHandle type, |
| | | 500 | | ushort packingSize, |
| | | 501 | | uint size) |
| | 0 | 502 | | { |
| | 0 | 503 | | _classLayoutTable.Add(new ClassLayoutRow |
| | 0 | 504 | | { |
| | 0 | 505 | | Parent = type.RowId, |
| | 0 | 506 | | PackingSize = packingSize, |
| | 0 | 507 | | ClassSize = size |
| | 0 | 508 | | }); |
| | 0 | 509 | | } |
| | | 510 | | |
| | | 511 | | /// <summary> |
| | | 512 | | /// Adds an interface implementation to a type. |
| | | 513 | | /// </summary> |
| | | 514 | | /// <param name="type">The type implementing the interface.</param> |
| | | 515 | | /// <param name="implementedInterface"> |
| | | 516 | | /// The interface being implemented: |
| | | 517 | | /// <see cref="TypeDefinitionHandle"/>, <see cref="TypeReferenceHandle"/> or <see cref="TypeSpecificationHandle" |
| | | 518 | | /// </param> |
| | | 519 | | /// <remarks> |
| | | 520 | | /// Interface implementations must be added in the same order as the corresponding type definitions implementing |
| | | 521 | | /// If a type implements multiple interfaces the corresponding entries must be added in the order determined by |
| | | 522 | | /// </remarks> |
| | | 523 | | /// <exception cref="ArgumentException"><paramref name="implementedInterface"/> doesn't have the expected handle |
| | | 524 | | public InterfaceImplementationHandle AddInterfaceImplementation( |
| | | 525 | | TypeDefinitionHandle type, |
| | | 526 | | EntityHandle implementedInterface) |
| | 0 | 527 | | { |
| | 0 | 528 | | _interfaceImplTable.Add(new InterfaceImplRow |
| | 0 | 529 | | { |
| | 0 | 530 | | Class = type.RowId, |
| | 0 | 531 | | Interface = CodedIndex.TypeDefOrRefOrSpec(implementedInterface) |
| | 0 | 532 | | }); |
| | | 533 | | |
| | 0 | 534 | | return InterfaceImplementationHandle.FromRowId(_interfaceImplTable.Count); |
| | 0 | 535 | | } |
| | | 536 | | |
| | | 537 | | /// <summary> |
| | | 538 | | /// Defines a nesting relationship to specified type definitions. |
| | | 539 | | /// </summary> |
| | | 540 | | /// <param name="type">The nested type definition handle.</param> |
| | | 541 | | /// <param name="enclosingType">The enclosing type definition handle.</param> |
| | | 542 | | /// <remarks> |
| | | 543 | | /// Entries must be added in the same order as the corresponding nested type definitions. |
| | | 544 | | /// </remarks> |
| | | 545 | | public void AddNestedType( |
| | | 546 | | TypeDefinitionHandle type, |
| | | 547 | | TypeDefinitionHandle enclosingType) |
| | 0 | 548 | | { |
| | 0 | 549 | | _nestedClassTable.Add(new NestedClassRow |
| | 0 | 550 | | { |
| | 0 | 551 | | NestedClass = type.RowId, |
| | 0 | 552 | | EnclosingClass = enclosingType.RowId |
| | 0 | 553 | | }); |
| | 0 | 554 | | } |
| | | 555 | | |
| | | 556 | | /// <summary> |
| | | 557 | | /// Add a type reference. |
| | | 558 | | /// </summary> |
| | | 559 | | /// <param name="resolutionScope"> |
| | | 560 | | /// The entity declaring the target type: |
| | | 561 | | /// <see cref="ModuleDefinitionHandle"/>, <see cref="ModuleReferenceHandle"/>, <see cref="AssemblyReferenceHandl |
| | | 562 | | /// </param> |
| | | 563 | | /// <param name="namespace">Namespace.</param> |
| | | 564 | | /// <param name="name">Type name.</param> |
| | | 565 | | /// <exception cref="ArgumentException"><paramref name="resolutionScope"/> doesn't have the expected handle kind |
| | | 566 | | public TypeReferenceHandle AddTypeReference( |
| | | 567 | | EntityHandle resolutionScope, |
| | | 568 | | StringHandle @namespace, |
| | | 569 | | StringHandle name) |
| | 0 | 570 | | { |
| | 0 | 571 | | _typeRefTable.Add(new TypeRefRow |
| | 0 | 572 | | { |
| | 0 | 573 | | ResolutionScope = resolutionScope.IsNil ? 0 : CodedIndex.ResolutionScope(resolutionScope), |
| | 0 | 574 | | Name = name, |
| | 0 | 575 | | Namespace = @namespace |
| | 0 | 576 | | }); |
| | | 577 | | |
| | 0 | 578 | | return TypeReferenceHandle.FromRowId(_typeRefTable.Count); |
| | 0 | 579 | | } |
| | | 580 | | |
| | | 581 | | public TypeSpecificationHandle AddTypeSpecification(BlobHandle signature) |
| | 0 | 582 | | { |
| | 0 | 583 | | _typeSpecTable.Add(new TypeSpecRow |
| | 0 | 584 | | { |
| | 0 | 585 | | Signature = signature |
| | 0 | 586 | | }); |
| | | 587 | | |
| | 0 | 588 | | return TypeSpecificationHandle.FromRowId(_typeSpecTable.Count); |
| | 0 | 589 | | } |
| | | 590 | | |
| | | 591 | | public StandaloneSignatureHandle AddStandaloneSignature(BlobHandle signature) |
| | 0 | 592 | | { |
| | 0 | 593 | | _standAloneSigTable.Add(new StandaloneSigRow |
| | 0 | 594 | | { |
| | 0 | 595 | | Signature = signature |
| | 0 | 596 | | }); |
| | | 597 | | |
| | 0 | 598 | | return StandaloneSignatureHandle.FromRowId(_standAloneSigTable.Count); |
| | 0 | 599 | | } |
| | | 600 | | |
| | | 601 | | /// <summary> |
| | | 602 | | /// Adds a property definition. |
| | | 603 | | /// </summary> |
| | | 604 | | /// <param name="attributes">Attributes</param> |
| | | 605 | | /// <param name="name">Name</param> |
| | | 606 | | /// <param name="signature">Signature of the property.</param> |
| | | 607 | | public PropertyDefinitionHandle AddProperty(PropertyAttributes attributes, StringHandle name, BlobHandle signatu |
| | 0 | 608 | | { |
| | 0 | 609 | | _propertyTable.Add(new PropertyRow |
| | 0 | 610 | | { |
| | 0 | 611 | | PropFlags = unchecked((ushort)attributes), |
| | 0 | 612 | | Name = name, |
| | 0 | 613 | | Type = signature |
| | 0 | 614 | | }); |
| | | 615 | | |
| | 0 | 616 | | return PropertyDefinitionHandle.FromRowId(_propertyTable.Count); |
| | 0 | 617 | | } |
| | | 618 | | |
| | | 619 | | public void AddPropertyMap(TypeDefinitionHandle declaringType, PropertyDefinitionHandle propertyList) |
| | 0 | 620 | | { |
| | 0 | 621 | | _propertyMapTable.Add(new PropertyMapRow |
| | 0 | 622 | | { |
| | 0 | 623 | | Parent = declaringType.RowId, |
| | 0 | 624 | | PropertyList = propertyList.RowId |
| | 0 | 625 | | }); |
| | 0 | 626 | | } |
| | | 627 | | |
| | | 628 | | /// <summary> |
| | | 629 | | /// Adds an event definition. |
| | | 630 | | /// </summary> |
| | | 631 | | /// <param name="attributes">Attributes</param> |
| | | 632 | | /// <param name="name">Name</param> |
| | | 633 | | /// <param name="type">Type of the event: <see cref="TypeDefinitionHandle"/>, <see cref="TypeReferenceHandle"/>, |
| | | 634 | | /// <exception cref="ArgumentException"><paramref name="type"/> doesn't have the expected handle kind.</exceptio |
| | | 635 | | public EventDefinitionHandle AddEvent(EventAttributes attributes, StringHandle name, EntityHandle type) |
| | 0 | 636 | | { |
| | 0 | 637 | | _eventTable.Add(new EventRow |
| | 0 | 638 | | { |
| | 0 | 639 | | EventFlags = unchecked((ushort)attributes), |
| | 0 | 640 | | Name = name, |
| | 0 | 641 | | EventType = CodedIndex.TypeDefOrRefOrSpec(type) |
| | 0 | 642 | | }); |
| | | 643 | | |
| | 0 | 644 | | return EventDefinitionHandle.FromRowId(_eventTable.Count); |
| | 0 | 645 | | } |
| | | 646 | | |
| | | 647 | | public void AddEventMap(TypeDefinitionHandle declaringType, EventDefinitionHandle eventList) |
| | 0 | 648 | | { |
| | 0 | 649 | | _eventMapTable.Add(new EventMapRow |
| | 0 | 650 | | { |
| | 0 | 651 | | Parent = declaringType.RowId, |
| | 0 | 652 | | EventList = eventList.RowId |
| | 0 | 653 | | }); |
| | 0 | 654 | | } |
| | | 655 | | |
| | | 656 | | /// <summary> |
| | | 657 | | /// Adds a default value for a parameter, field or property. |
| | | 658 | | /// </summary> |
| | | 659 | | /// <param name="parent"><see cref="ParameterHandle"/>, <see cref="FieldDefinitionHandle"/>, or <see cref="Prope |
| | | 660 | | /// <param name="value">The constant value.</param> |
| | | 661 | | /// <remarks> |
| | | 662 | | /// Entries may be added in any order. The table is automatically sorted when serialized. |
| | | 663 | | /// </remarks> |
| | | 664 | | /// <exception cref="ArgumentException"><paramref name="parent"/> doesn't have the expected handle kind.</except |
| | | 665 | | public ConstantHandle AddConstant(EntityHandle parent, object? value) |
| | 0 | 666 | | { |
| | 0 | 667 | | int parentCodedIndex = CodedIndex.HasConstant(parent); |
| | | 668 | | |
| | | 669 | | // the table is required to be sorted by Parent: |
| | 0 | 670 | | _constantTableNeedsSorting |= parentCodedIndex < _constantTableLastParent; |
| | 0 | 671 | | _constantTableLastParent = parentCodedIndex; |
| | | 672 | | |
| | 0 | 673 | | _constantTable.Add(new ConstantRow |
| | 0 | 674 | | { |
| | 0 | 675 | | Type = (byte)MetadataWriterUtilities.GetConstantTypeCode(value), |
| | 0 | 676 | | Parent = parentCodedIndex, |
| | 0 | 677 | | Value = GetOrAddConstantBlob(value) |
| | 0 | 678 | | }); |
| | | 679 | | |
| | 0 | 680 | | return ConstantHandle.FromRowId(_constantTable.Count); |
| | 0 | 681 | | } |
| | | 682 | | |
| | | 683 | | /// <summary> |
| | | 684 | | /// Associates a method (a getter, a setter, an adder, etc.) with a property or an event. |
| | | 685 | | /// </summary> |
| | | 686 | | /// <param name="association"><see cref="EventDefinitionHandle"/> or <see cref="PropertyDefinitionHandle"/>.</pa |
| | | 687 | | /// <param name="semantics">Semantics.</param> |
| | | 688 | | /// <param name="methodDefinition">Method definition.</param> |
| | | 689 | | /// <exception cref="ArgumentException"><paramref name="association"/> doesn't have the expected handle kind.</e |
| | | 690 | | /// <remarks> |
| | | 691 | | /// Entries may be added in any order. The table is automatically sorted when serialized. |
| | | 692 | | /// </remarks> |
| | | 693 | | public void AddMethodSemantics(EntityHandle association, MethodSemanticsAttributes semantics, MethodDefinitionHa |
| | 0 | 694 | | { |
| | 0 | 695 | | int associationCodedIndex = CodedIndex.HasSemantics(association); |
| | | 696 | | |
| | | 697 | | // the table is required to be sorted by Association: |
| | 0 | 698 | | _methodSemanticsTableNeedsSorting |= associationCodedIndex < _methodSemanticsTableLastAssociation; |
| | 0 | 699 | | _methodSemanticsTableLastAssociation = associationCodedIndex; |
| | | 700 | | |
| | 0 | 701 | | _methodSemanticsTable.Add(new MethodSemanticsRow |
| | 0 | 702 | | { |
| | 0 | 703 | | Association = associationCodedIndex, |
| | 0 | 704 | | Method = methodDefinition.RowId, |
| | 0 | 705 | | Semantic = unchecked((ushort)semantics) |
| | 0 | 706 | | }); |
| | 0 | 707 | | } |
| | | 708 | | |
| | | 709 | | /// <summary> |
| | | 710 | | /// Add a custom attribute. |
| | | 711 | | /// </summary> |
| | | 712 | | /// <param name="parent"> |
| | | 713 | | /// An entity to attach the custom attribute to: |
| | | 714 | | /// <see cref="MethodDefinitionHandle"/>, |
| | | 715 | | /// <see cref="FieldDefinitionHandle"/>, |
| | | 716 | | /// <see cref="TypeReferenceHandle"/>, |
| | | 717 | | /// <see cref="TypeDefinitionHandle"/>, |
| | | 718 | | /// <see cref="ParameterHandle"/>, |
| | | 719 | | /// <see cref="InterfaceImplementationHandle"/>, |
| | | 720 | | /// <see cref="MemberReferenceHandle"/>, |
| | | 721 | | /// <see cref="ModuleDefinitionHandle"/>, |
| | | 722 | | /// <see cref="DeclarativeSecurityAttributeHandle"/>, |
| | | 723 | | /// <see cref="PropertyDefinitionHandle"/>, |
| | | 724 | | /// <see cref="EventDefinitionHandle"/>, |
| | | 725 | | /// <see cref="StandaloneSignatureHandle"/>, |
| | | 726 | | /// <see cref="ModuleReferenceHandle"/>, |
| | | 727 | | /// <see cref="TypeSpecificationHandle"/>, |
| | | 728 | | /// <see cref="AssemblyDefinitionHandle"/>, |
| | | 729 | | /// <see cref="AssemblyReferenceHandle"/>, |
| | | 730 | | /// <see cref="AssemblyFileHandle"/>, |
| | | 731 | | /// <see cref="ExportedTypeHandle"/>, |
| | | 732 | | /// <see cref="ManifestResourceHandle"/>, |
| | | 733 | | /// <see cref="GenericParameterHandle"/>, |
| | | 734 | | /// <see cref="GenericParameterConstraintHandle"/> or |
| | | 735 | | /// <see cref="MethodSpecificationHandle"/>. |
| | | 736 | | /// </param> |
| | | 737 | | /// <param name="constructor"> |
| | | 738 | | /// Custom attribute constructor: <see cref="MethodDefinitionHandle"/> or <see cref="MemberReferenceHandle"/> |
| | | 739 | | /// </param> |
| | | 740 | | /// <param name="value"> |
| | | 741 | | /// Custom attribute value blob. |
| | | 742 | | /// </param> |
| | | 743 | | /// <remarks> |
| | | 744 | | /// Entries may be added in any order. The table is automatically sorted when serialized. |
| | | 745 | | /// </remarks> |
| | | 746 | | /// <exception cref="ArgumentException"><paramref name="parent"/> doesn't have the expected handle kind.</except |
| | | 747 | | public CustomAttributeHandle AddCustomAttribute(EntityHandle parent, EntityHandle constructor, BlobHandle value) |
| | 0 | 748 | | { |
| | 0 | 749 | | int parentCodedIndex = CodedIndex.HasCustomAttribute(parent); |
| | | 750 | | |
| | | 751 | | // the table is required to be sorted by Parent: |
| | 0 | 752 | | _customAttributeTableNeedsSorting |= parentCodedIndex < _customAttributeTableLastParent; |
| | 0 | 753 | | _customAttributeTableLastParent = parentCodedIndex; |
| | | 754 | | |
| | 0 | 755 | | _customAttributeTable.Add(new CustomAttributeRow |
| | 0 | 756 | | { |
| | 0 | 757 | | Parent = parentCodedIndex, |
| | 0 | 758 | | Type = CodedIndex.CustomAttributeType(constructor), |
| | 0 | 759 | | Value = value |
| | 0 | 760 | | }); |
| | | 761 | | |
| | 0 | 762 | | return CustomAttributeHandle.FromRowId(_customAttributeTable.Count); |
| | 0 | 763 | | } |
| | | 764 | | |
| | | 765 | | /// <summary> |
| | | 766 | | /// Adds a method specification (instantiation). |
| | | 767 | | /// </summary> |
| | | 768 | | /// <param name="method">Generic method: <see cref="MethodDefinitionHandle"/> or <see cref="MemberReferenceHandl |
| | | 769 | | /// <param name="instantiation">Instantiation blob encoding the generic arguments of the method.</param> |
| | | 770 | | /// <exception cref="ArgumentException"><paramref name="method"/> doesn't have the expected handle kind.</except |
| | | 771 | | public MethodSpecificationHandle AddMethodSpecification(EntityHandle method, BlobHandle instantiation) |
| | 0 | 772 | | { |
| | 0 | 773 | | _methodSpecTable.Add(new MethodSpecRow |
| | 0 | 774 | | { |
| | 0 | 775 | | Method = CodedIndex.MethodDefOrRef(method), |
| | 0 | 776 | | Instantiation = instantiation |
| | 0 | 777 | | }); |
| | | 778 | | |
| | 0 | 779 | | return MethodSpecificationHandle.FromRowId(_methodSpecTable.Count); |
| | 0 | 780 | | } |
| | | 781 | | |
| | | 782 | | public ModuleReferenceHandle AddModuleReference(StringHandle moduleName) |
| | 0 | 783 | | { |
| | 0 | 784 | | _moduleRefTable.Add(new ModuleRefRow |
| | 0 | 785 | | { |
| | 0 | 786 | | Name = moduleName |
| | 0 | 787 | | }); |
| | | 788 | | |
| | 0 | 789 | | return ModuleReferenceHandle.FromRowId(_moduleRefTable.Count); |
| | 0 | 790 | | } |
| | | 791 | | |
| | | 792 | | /// <summary> |
| | | 793 | | /// Adds a parameter definition. |
| | | 794 | | /// </summary> |
| | | 795 | | /// <param name="attributes"><see cref="ParameterAttributes"/></param> |
| | | 796 | | /// <param name="name">Parameter name (optional).</param> |
| | | 797 | | /// <param name="sequenceNumber">Sequence number of the parameter. Value of 0 refers to the owner method's retur |
| | | 798 | | /// <exception cref="ArgumentOutOfRangeException"><paramref name="sequenceNumber"/> is greater than <see cref="u |
| | | 799 | | public ParameterHandle AddParameter(ParameterAttributes attributes, StringHandle name, int sequenceNumber) |
| | 0 | 800 | | { |
| | 0 | 801 | | if (unchecked((uint)sequenceNumber) > ushort.MaxValue) |
| | 0 | 802 | | { |
| | 0 | 803 | | Throw.ArgumentOutOfRange(nameof(sequenceNumber)); |
| | | 804 | | } |
| | | 805 | | |
| | 0 | 806 | | _paramTable.Add(new ParamRow |
| | 0 | 807 | | { |
| | 0 | 808 | | Flags = unchecked((ushort)attributes), |
| | 0 | 809 | | Name = name, |
| | 0 | 810 | | Sequence = (ushort)sequenceNumber |
| | 0 | 811 | | }); |
| | | 812 | | |
| | 0 | 813 | | return ParameterHandle.FromRowId(_paramTable.Count); |
| | 0 | 814 | | } |
| | | 815 | | |
| | | 816 | | /// <summary> |
| | | 817 | | /// Adds a generic parameter definition. |
| | | 818 | | /// </summary> |
| | | 819 | | /// <param name="parent">Parent entity handle: <see cref="TypeDefinitionHandle"/> or <see cref="MethodDefinition |
| | | 820 | | /// <param name="attributes">Attributes.</param> |
| | | 821 | | /// <param name="name">Parameter name.</param> |
| | | 822 | | /// <param name="index">Zero-based parameter index.</param> |
| | | 823 | | /// <remarks> |
| | | 824 | | /// Generic parameters must be added in an order determined by the coded index of their parent entity (<see cref |
| | | 825 | | /// Generic parameters with the same parent must be ordered by their <paramref name="index"/>. |
| | | 826 | | /// </remarks> |
| | | 827 | | /// <exception cref="ArgumentException"><paramref name="parent"/> doesn't have the expected handle kind.</except |
| | | 828 | | /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is greater than <see cref="ushort.Max |
| | | 829 | | public GenericParameterHandle AddGenericParameter( |
| | | 830 | | EntityHandle parent, |
| | | 831 | | GenericParameterAttributes attributes, |
| | | 832 | | StringHandle name, |
| | | 833 | | int index) |
| | 0 | 834 | | { |
| | 0 | 835 | | if (unchecked((uint)index) > ushort.MaxValue) |
| | 0 | 836 | | { |
| | 0 | 837 | | Throw.ArgumentOutOfRange(nameof(index)); |
| | | 838 | | } |
| | | 839 | | |
| | 0 | 840 | | _genericParamTable.Add(new GenericParamRow |
| | 0 | 841 | | { |
| | 0 | 842 | | Flags = unchecked((ushort)attributes), |
| | 0 | 843 | | Name = name, |
| | 0 | 844 | | Number = (ushort)index, |
| | 0 | 845 | | Owner = CodedIndex.TypeOrMethodDef(parent) |
| | 0 | 846 | | }); |
| | | 847 | | |
| | 0 | 848 | | return GenericParameterHandle.FromRowId(_genericParamTable.Count); |
| | 0 | 849 | | } |
| | | 850 | | |
| | | 851 | | /// <summary> |
| | | 852 | | /// Adds a type constraint to a generic parameter. |
| | | 853 | | /// </summary> |
| | | 854 | | /// <param name="genericParameter">Generic parameter to constrain.</param> |
| | | 855 | | /// <param name="constraint">Type constraint: <see cref="TypeDefinitionHandle"/>, <see cref="TypeReferenceHandle |
| | | 856 | | /// <exception cref="ArgumentException"><paramref name="genericParameter"/> doesn't have the expected handle kin |
| | | 857 | | /// <remarks> |
| | | 858 | | /// Constraints must be added in the same order as the corresponding generic parameters. |
| | | 859 | | /// </remarks> |
| | | 860 | | public GenericParameterConstraintHandle AddGenericParameterConstraint( |
| | | 861 | | GenericParameterHandle genericParameter, |
| | | 862 | | EntityHandle constraint) |
| | 0 | 863 | | { |
| | 0 | 864 | | _genericParamConstraintTable.Add(new GenericParamConstraintRow |
| | 0 | 865 | | { |
| | 0 | 866 | | Owner = genericParameter.RowId, |
| | 0 | 867 | | Constraint = CodedIndex.TypeDefOrRefOrSpec(constraint), |
| | 0 | 868 | | }); |
| | | 869 | | |
| | 0 | 870 | | return GenericParameterConstraintHandle.FromRowId(_genericParamConstraintTable.Count); |
| | 0 | 871 | | } |
| | | 872 | | |
| | | 873 | | /// <summary> |
| | | 874 | | /// Adds a field definition. |
| | | 875 | | /// </summary> |
| | | 876 | | /// <param name="attributes">Field attributes.</param> |
| | | 877 | | /// <param name="name">Field name.</param> |
| | | 878 | | /// <param name="signature">Field signature. Use <see cref="BlobEncoder.FieldSignature"/> to construct the blob. |
| | | 879 | | public FieldDefinitionHandle AddFieldDefinition( |
| | | 880 | | FieldAttributes attributes, |
| | | 881 | | StringHandle name, |
| | | 882 | | BlobHandle signature) |
| | 0 | 883 | | { |
| | 0 | 884 | | _fieldTable.Add(new FieldDefRow |
| | 0 | 885 | | { |
| | 0 | 886 | | Flags = unchecked((ushort)attributes), |
| | 0 | 887 | | Name = name, |
| | 0 | 888 | | Signature = signature |
| | 0 | 889 | | }); |
| | | 890 | | |
| | 0 | 891 | | return FieldDefinitionHandle.FromRowId(_fieldTable.Count); |
| | 0 | 892 | | } |
| | | 893 | | |
| | | 894 | | /// <summary> |
| | | 895 | | /// Defines a field layout of a field definition. |
| | | 896 | | /// </summary> |
| | | 897 | | /// <param name="field">Field definition.</param> |
| | | 898 | | /// <param name="offset">The byte offset of the field within the declaring type instance.</param> |
| | | 899 | | /// <remarks> |
| | | 900 | | /// Entries must be added in the same order as the corresponding field definitions. |
| | | 901 | | /// </remarks> |
| | | 902 | | public void AddFieldLayout( |
| | | 903 | | FieldDefinitionHandle field, |
| | | 904 | | int offset) |
| | 0 | 905 | | { |
| | 0 | 906 | | _fieldLayoutTable.Add(new FieldLayoutRow |
| | 0 | 907 | | { |
| | 0 | 908 | | Field = field.RowId, |
| | 0 | 909 | | Offset = offset |
| | 0 | 910 | | }); |
| | 0 | 911 | | } |
| | | 912 | | |
| | | 913 | | /// <summary> |
| | | 914 | | /// Add marshalling information to a field or a parameter. |
| | | 915 | | /// </summary> |
| | | 916 | | /// <param name="parent"><see cref="ParameterHandle"/> or <see cref="FieldDefinitionHandle"/>.</param> |
| | | 917 | | /// <param name="descriptor">Descriptor blob.</param> |
| | | 918 | | /// <exception cref="ArgumentException"><paramref name="parent"/> doesn't have the expected handle kind.</except |
| | | 919 | | /// <remarks> |
| | | 920 | | /// Entries may be added in any order. The table is automatically sorted when serialized. |
| | | 921 | | /// </remarks> |
| | | 922 | | public void AddMarshallingDescriptor( |
| | | 923 | | EntityHandle parent, |
| | | 924 | | BlobHandle descriptor) |
| | 0 | 925 | | { |
| | 0 | 926 | | int codedIndex = CodedIndex.HasFieldMarshal(parent); |
| | | 927 | | |
| | | 928 | | // the table is required to be sorted by Parent: |
| | 0 | 929 | | _fieldMarshalTableNeedsSorting |= codedIndex < _fieldMarshalTableLastParent; |
| | 0 | 930 | | _fieldMarshalTableLastParent = codedIndex; |
| | | 931 | | |
| | 0 | 932 | | _fieldMarshalTable.Add(new FieldMarshalRow |
| | 0 | 933 | | { |
| | 0 | 934 | | Parent = codedIndex, |
| | 0 | 935 | | NativeType = descriptor |
| | 0 | 936 | | }); |
| | 0 | 937 | | } |
| | | 938 | | |
| | | 939 | | /// <summary> |
| | | 940 | | /// Adds a mapping from a field to its initial value stored in the PE image. |
| | | 941 | | /// </summary> |
| | | 942 | | /// <param name="field">Field definition handle.</param> |
| | | 943 | | /// <param name="offset"> |
| | | 944 | | /// Offset within the block in the PE image that stores initial values of mapped fields (usually in .text sectio |
| | | 945 | | /// The final relative virtual address stored in the metadata is calculated when the metadata is serialized |
| | | 946 | | /// by adding the offset to the virtual address of the block start. |
| | | 947 | | /// </param> |
| | | 948 | | /// <remarks> |
| | | 949 | | /// Entries must be added in the same order as the corresponding field definitions. |
| | | 950 | | /// </remarks> |
| | | 951 | | /// <exception cref="ArgumentOutOfRangeException"><paramref name="offset"/> is negative.</exception> |
| | | 952 | | public void AddFieldRelativeVirtualAddress(FieldDefinitionHandle field, int offset) |
| | 0 | 953 | | { |
| | 0 | 954 | | if (offset < 0) |
| | 0 | 955 | | { |
| | 0 | 956 | | Throw.ArgumentOutOfRange(nameof(offset)); |
| | | 957 | | } |
| | | 958 | | |
| | 0 | 959 | | _fieldRvaTable.Add(new FieldRvaRow |
| | 0 | 960 | | { |
| | 0 | 961 | | Field = field.RowId, |
| | 0 | 962 | | Offset = offset |
| | 0 | 963 | | }); |
| | 0 | 964 | | } |
| | | 965 | | |
| | | 966 | | /// <summary> |
| | | 967 | | /// Adds a method definition. |
| | | 968 | | /// </summary> |
| | | 969 | | /// <param name="attributes"><see cref="MethodAttributes"/></param> |
| | | 970 | | /// <param name="implAttributes"><see cref="MethodImplAttributes"/></param> |
| | | 971 | | /// <param name="name">Method name/</param> |
| | | 972 | | /// <param name="signature">Method signature.</param> |
| | | 973 | | /// <param name="bodyOffset"> |
| | | 974 | | /// Offset within the block in the PE image that stores method bodies (IL stream), |
| | | 975 | | /// or -1 if the method doesn't have a body. |
| | | 976 | | /// |
| | | 977 | | /// The final relative virtual address stored in the metadata is calculated when the metadata is serialized |
| | | 978 | | /// by adding the offset to the virtual address of the beginning of the block. |
| | | 979 | | /// </param> |
| | | 980 | | /// <param name="parameterList"> |
| | | 981 | | /// If the method declares parameters in Params table the handle of the first one, otherwise the handle of the f |
| | | 982 | | /// If no parameters are declared in the module, <see cref="MetadataTokens.ParameterHandle(int)"/>(1). |
| | | 983 | | /// </param> |
| | | 984 | | /// <exception cref="ArgumentOutOfRangeException"><paramref name="bodyOffset"/> is less than -1.</exception> |
| | | 985 | | public MethodDefinitionHandle AddMethodDefinition( |
| | | 986 | | MethodAttributes attributes, |
| | | 987 | | MethodImplAttributes implAttributes, |
| | | 988 | | StringHandle name, |
| | | 989 | | BlobHandle signature, |
| | | 990 | | int bodyOffset, |
| | | 991 | | ParameterHandle parameterList) |
| | 0 | 992 | | { |
| | 0 | 993 | | if (bodyOffset < -1) |
| | 0 | 994 | | { |
| | 0 | 995 | | Throw.ArgumentOutOfRange(nameof(bodyOffset)); |
| | | 996 | | } |
| | | 997 | | |
| | 0 | 998 | | _methodDefTable.Add(new MethodRow |
| | 0 | 999 | | { |
| | 0 | 1000 | | Flags = unchecked((ushort)attributes), |
| | 0 | 1001 | | ImplFlags = unchecked((ushort)implAttributes), |
| | 0 | 1002 | | Name = name, |
| | 0 | 1003 | | Signature = signature, |
| | 0 | 1004 | | BodyOffset = bodyOffset, |
| | 0 | 1005 | | ParamList = parameterList.RowId |
| | 0 | 1006 | | }); |
| | | 1007 | | |
| | 0 | 1008 | | return MethodDefinitionHandle.FromRowId(_methodDefTable.Count); |
| | 0 | 1009 | | } |
| | | 1010 | | |
| | | 1011 | | /// <summary> |
| | | 1012 | | /// Adds import information to a method definition (P/Invoke). |
| | | 1013 | | /// </summary> |
| | | 1014 | | /// <param name="method">Method definition handle.</param> |
| | | 1015 | | /// <param name="attributes">Attributes.</param> |
| | | 1016 | | /// <param name="name">Unmanaged method name.</param> |
| | | 1017 | | /// <param name="module">Module containing the unmanaged method.</param> |
| | | 1018 | | /// <remarks> |
| | | 1019 | | /// Method imports must be added in the same order as the corresponding method definitions. |
| | | 1020 | | /// </remarks> |
| | | 1021 | | public void AddMethodImport( |
| | | 1022 | | MethodDefinitionHandle method, |
| | | 1023 | | MethodImportAttributes attributes, |
| | | 1024 | | StringHandle name, |
| | | 1025 | | ModuleReferenceHandle module) |
| | 0 | 1026 | | { |
| | 0 | 1027 | | _implMapTable.Add(new ImplMapRow |
| | 0 | 1028 | | { |
| | 0 | 1029 | | MemberForwarded = CodedIndex.MemberForwarded(method), |
| | 0 | 1030 | | ImportName = name, |
| | 0 | 1031 | | ImportScope = module.RowId, |
| | 0 | 1032 | | MappingFlags = unchecked((ushort)attributes), |
| | 0 | 1033 | | }); |
| | 0 | 1034 | | } |
| | | 1035 | | |
| | | 1036 | | /// <summary> |
| | | 1037 | | /// Defines an implementation for a method declaration within a type. |
| | | 1038 | | /// </summary> |
| | | 1039 | | /// <param name="type">Type</param> |
| | | 1040 | | /// <param name="methodBody"><see cref="MethodDefinitionHandle"/> or <see cref="MemberReferenceHandle"/> which p |
| | | 1041 | | /// <param name="methodDeclaration"><see cref="MethodDefinitionHandle"/> or <see cref="MemberReferenceHandle"/> |
| | | 1042 | | /// <remarks> |
| | | 1043 | | /// Method implementations must be added in the same order as the corresponding type definitions. |
| | | 1044 | | /// </remarks> |
| | | 1045 | | /// <exception cref="ArgumentException"><paramref name="methodBody"/> or <paramref name="methodDeclaration"/> do |
| | | 1046 | | public MethodImplementationHandle AddMethodImplementation( |
| | | 1047 | | TypeDefinitionHandle type, |
| | | 1048 | | EntityHandle methodBody, |
| | | 1049 | | EntityHandle methodDeclaration) |
| | 0 | 1050 | | { |
| | 0 | 1051 | | _methodImplTable.Add(new MethodImplRow |
| | 0 | 1052 | | { |
| | 0 | 1053 | | Class = type.RowId, |
| | 0 | 1054 | | MethodBody = CodedIndex.MethodDefOrRef(methodBody), |
| | 0 | 1055 | | MethodDecl = CodedIndex.MethodDefOrRef(methodDeclaration) |
| | 0 | 1056 | | }); |
| | | 1057 | | |
| | 0 | 1058 | | return MethodImplementationHandle.FromRowId(_methodImplTable.Count); |
| | 0 | 1059 | | } |
| | | 1060 | | |
| | | 1061 | | /// <summary> |
| | | 1062 | | /// Adds a MemberRef table row. |
| | | 1063 | | /// </summary> |
| | | 1064 | | /// <param name="parent">Containing entity: |
| | | 1065 | | /// <see cref="TypeDefinitionHandle"/>, |
| | | 1066 | | /// <see cref="TypeReferenceHandle"/>, |
| | | 1067 | | /// <see cref="ModuleReferenceHandle"/>, |
| | | 1068 | | /// <see cref="MethodDefinitionHandle"/>, or |
| | | 1069 | | /// <see cref="TypeSpecificationHandle"/>. |
| | | 1070 | | /// </param> |
| | | 1071 | | /// <param name="name">Member name.</param> |
| | | 1072 | | /// <param name="signature">Member signature.</param> |
| | | 1073 | | /// <exception cref="ArgumentException"><paramref name="parent"/> doesn't have the expected handle kind.</except |
| | | 1074 | | public MemberReferenceHandle AddMemberReference( |
| | | 1075 | | EntityHandle parent, |
| | | 1076 | | StringHandle name, |
| | | 1077 | | BlobHandle signature) |
| | 0 | 1078 | | { |
| | 0 | 1079 | | _memberRefTable.Add(new MemberRefRow |
| | 0 | 1080 | | { |
| | 0 | 1081 | | Class = CodedIndex.MemberRefParent(parent), |
| | 0 | 1082 | | Name = name, |
| | 0 | 1083 | | Signature = signature |
| | 0 | 1084 | | }); |
| | | 1085 | | |
| | 0 | 1086 | | return MemberReferenceHandle.FromRowId(_memberRefTable.Count); |
| | 0 | 1087 | | } |
| | | 1088 | | |
| | | 1089 | | /// <summary> |
| | | 1090 | | /// Adds a manifest resource. |
| | | 1091 | | /// </summary> |
| | | 1092 | | /// <param name="attributes">Attributes</param> |
| | | 1093 | | /// <param name="name">Resource name</param> |
| | | 1094 | | /// <param name="implementation"><see cref="AssemblyFileHandle"/>, <see cref="AssemblyReferenceHandle"/>, or nil |
| | | 1095 | | /// <param name="offset">Specifies the byte offset within the referenced file at which this resource record begi |
| | | 1096 | | /// <exception cref="ArgumentException"><paramref name="implementation"/> doesn't have the expected handle kind. |
| | | 1097 | | public ManifestResourceHandle AddManifestResource( |
| | | 1098 | | ManifestResourceAttributes attributes, |
| | | 1099 | | StringHandle name, |
| | | 1100 | | EntityHandle implementation, |
| | | 1101 | | uint offset) |
| | 0 | 1102 | | { |
| | 0 | 1103 | | _manifestResourceTable.Add(new ManifestResourceRow |
| | 0 | 1104 | | { |
| | 0 | 1105 | | Flags = unchecked((uint)attributes), |
| | 0 | 1106 | | Name = name, |
| | 0 | 1107 | | Implementation = implementation.IsNil ? 0 : CodedIndex.Implementation(implementation), |
| | 0 | 1108 | | Offset = offset |
| | 0 | 1109 | | }); |
| | | 1110 | | |
| | 0 | 1111 | | return ManifestResourceHandle.FromRowId(_manifestResourceTable.Count); |
| | 0 | 1112 | | } |
| | | 1113 | | |
| | | 1114 | | public AssemblyFileHandle AddAssemblyFile( |
| | | 1115 | | StringHandle name, |
| | | 1116 | | BlobHandle hashValue, |
| | | 1117 | | bool containsMetadata) |
| | 0 | 1118 | | { |
| | 0 | 1119 | | _fileTable.Add(new FileTableRow |
| | 0 | 1120 | | { |
| | 0 | 1121 | | FileName = name, |
| | 0 | 1122 | | Flags = containsMetadata ? 0u : 1u, |
| | 0 | 1123 | | HashValue = hashValue |
| | 0 | 1124 | | }); |
| | | 1125 | | |
| | 0 | 1126 | | return AssemblyFileHandle.FromRowId(_fileTable.Count); |
| | 0 | 1127 | | } |
| | | 1128 | | |
| | | 1129 | | /// <summary> |
| | | 1130 | | /// Adds an exported type. |
| | | 1131 | | /// </summary> |
| | | 1132 | | /// <param name="attributes">Attributes</param> |
| | | 1133 | | /// <param name="namespace">Namespace</param> |
| | | 1134 | | /// <param name="name">Type name</param> |
| | | 1135 | | /// <param name="implementation"><see cref="AssemblyFileHandle"/>, <see cref="ExportedTypeHandle"/> or <see cref |
| | | 1136 | | /// <param name="typeDefinitionId">Type definition id</param> |
| | | 1137 | | /// <exception cref="ArgumentException"><paramref name="implementation"/> doesn't have the expected handle kind. |
| | | 1138 | | public ExportedTypeHandle AddExportedType( |
| | | 1139 | | TypeAttributes attributes, |
| | | 1140 | | StringHandle @namespace, |
| | | 1141 | | StringHandle name, |
| | | 1142 | | EntityHandle implementation, |
| | | 1143 | | int typeDefinitionId) |
| | 0 | 1144 | | { |
| | 0 | 1145 | | _exportedTypeTable.Add(new ExportedTypeRow |
| | 0 | 1146 | | { |
| | 0 | 1147 | | Flags = unchecked((uint)attributes), |
| | 0 | 1148 | | Implementation = CodedIndex.Implementation(implementation), |
| | 0 | 1149 | | TypeNamespace = @namespace, |
| | 0 | 1150 | | TypeName = name, |
| | 0 | 1151 | | TypeDefId = typeDefinitionId |
| | 0 | 1152 | | }); |
| | | 1153 | | |
| | 0 | 1154 | | return ExportedTypeHandle.FromRowId(_exportedTypeTable.Count); |
| | 0 | 1155 | | } |
| | | 1156 | | |
| | | 1157 | | /// <summary> |
| | | 1158 | | /// Adds declarative security attribute to a type, method or an assembly. |
| | | 1159 | | /// </summary> |
| | | 1160 | | /// <param name="parent"><see cref="TypeDefinitionHandle"/>, <see cref="MethodDefinitionHandle"/>, or <see cref= |
| | | 1161 | | /// <param name="action">Security action</param> |
| | | 1162 | | /// <param name="permissionSet">Permission set blob.</param> |
| | | 1163 | | /// <exception cref="ArgumentException"><paramref name="parent"/> doesn't have the expected handle kind.</except |
| | | 1164 | | /// <remarks> |
| | | 1165 | | /// Entries may be added in any order. The table is automatically sorted when serialized. |
| | | 1166 | | /// </remarks> |
| | | 1167 | | public DeclarativeSecurityAttributeHandle AddDeclarativeSecurityAttribute( |
| | | 1168 | | EntityHandle parent, |
| | | 1169 | | DeclarativeSecurityAction action, |
| | | 1170 | | BlobHandle permissionSet) |
| | 0 | 1171 | | { |
| | 0 | 1172 | | int parentCodedIndex = CodedIndex.HasDeclSecurity(parent); |
| | | 1173 | | |
| | | 1174 | | // the table is required to be sorted by Parent: |
| | 0 | 1175 | | _declSecurityTableNeedsSorting |= parentCodedIndex < _declSecurityTableLastParent; |
| | 0 | 1176 | | _declSecurityTableLastParent = parentCodedIndex; |
| | | 1177 | | |
| | 0 | 1178 | | _declSecurityTable.Add(new DeclSecurityRow |
| | 0 | 1179 | | { |
| | 0 | 1180 | | Parent = parentCodedIndex, |
| | 0 | 1181 | | Action = unchecked((ushort)action), |
| | 0 | 1182 | | PermissionSet = permissionSet |
| | 0 | 1183 | | }); |
| | | 1184 | | |
| | 0 | 1185 | | return DeclarativeSecurityAttributeHandle.FromRowId(_declSecurityTable.Count); |
| | 0 | 1186 | | } |
| | | 1187 | | |
| | | 1188 | | public void AddEncLogEntry(EntityHandle entity, EditAndContinueOperation code) |
| | 0 | 1189 | | { |
| | 0 | 1190 | | _encLogTable.Add(new EncLogRow |
| | 0 | 1191 | | { |
| | 0 | 1192 | | Token = entity.Token, |
| | 0 | 1193 | | FuncCode = unchecked((byte)code) |
| | 0 | 1194 | | }); |
| | 0 | 1195 | | } |
| | | 1196 | | |
| | | 1197 | | public void AddEncMapEntry(EntityHandle entity) |
| | 0 | 1198 | | { |
| | 0 | 1199 | | _encMapTable.Add(new EncMapRow |
| | 0 | 1200 | | { |
| | 0 | 1201 | | Token = entity.Token |
| | 0 | 1202 | | }); |
| | 0 | 1203 | | } |
| | | 1204 | | |
| | | 1205 | | /// <summary> |
| | | 1206 | | /// Add document debug information. |
| | | 1207 | | /// </summary> |
| | | 1208 | | /// <param name="name"> |
| | | 1209 | | /// Document Name blob. |
| | | 1210 | | /// </param> |
| | | 1211 | | /// <param name="hashAlgorithm"> |
| | | 1212 | | /// GUID of the hash algorithm used to calculate the value of <paramref name="hash"/>. |
| | | 1213 | | /// </param> |
| | | 1214 | | /// <param name="hash"> |
| | | 1215 | | /// The hash of the document content. |
| | | 1216 | | /// </param> |
| | | 1217 | | /// <param name="language"> |
| | | 1218 | | /// GUID of the language. |
| | | 1219 | | /// </param> |
| | | 1220 | | /// See https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.Metadata/specs/PortablePdb-M |
| | | 1221 | | public DocumentHandle AddDocument(BlobHandle name, GuidHandle hashAlgorithm, BlobHandle hash, GuidHandle languag |
| | 0 | 1222 | | { |
| | 0 | 1223 | | _documentTable.Add(new DocumentRow |
| | 0 | 1224 | | { |
| | 0 | 1225 | | Name = name, |
| | 0 | 1226 | | HashAlgorithm = hashAlgorithm, |
| | 0 | 1227 | | Hash = hash, |
| | 0 | 1228 | | Language = language |
| | 0 | 1229 | | }); |
| | | 1230 | | |
| | 0 | 1231 | | return DocumentHandle.FromRowId(_documentTable.Count); |
| | 0 | 1232 | | } |
| | | 1233 | | |
| | | 1234 | | /// <summary> |
| | | 1235 | | /// Add method debug information. |
| | | 1236 | | /// </summary> |
| | | 1237 | | /// <param name="document"> |
| | | 1238 | | /// The handle of a single document containing all sequence points of the method, or nil if the method doesn't h |
| | | 1239 | | /// </param> |
| | | 1240 | | /// <param name="sequencePoints"> |
| | | 1241 | | /// Sequence Points blob, or nil if the method doesn't have sequence points. |
| | | 1242 | | /// See https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.Metadata/specs/PortablePdb-M |
| | | 1243 | | /// </param> |
| | | 1244 | | public MethodDebugInformationHandle AddMethodDebugInformation(DocumentHandle document, BlobHandle sequencePoints |
| | 0 | 1245 | | { |
| | 0 | 1246 | | _methodDebugInformationTable.Add(new MethodDebugInformationRow |
| | 0 | 1247 | | { |
| | 0 | 1248 | | Document = document.RowId, |
| | 0 | 1249 | | SequencePoints = sequencePoints |
| | 0 | 1250 | | }); |
| | | 1251 | | |
| | 0 | 1252 | | return MethodDebugInformationHandle.FromRowId(_methodDebugInformationTable.Count); |
| | 0 | 1253 | | } |
| | | 1254 | | |
| | | 1255 | | /// <summary> |
| | | 1256 | | /// Add local scope debug information. |
| | | 1257 | | /// </summary> |
| | | 1258 | | /// <param name="method">The containing method.</param> |
| | | 1259 | | /// <param name="importScope">Handle of the associated import scope.</param> |
| | | 1260 | | /// <param name="variableList"> |
| | | 1261 | | /// If the scope declares variables the handle of the first one, otherwise the handle of the first variable decl |
| | | 1262 | | /// If no scope defines any variables, <see cref="MetadataTokens.LocalVariableHandle(int)"/>(1). |
| | | 1263 | | /// </param> |
| | | 1264 | | /// <param name="constantList"> |
| | | 1265 | | /// If the scope declares constants the handle of the first one, otherwise the handle of the first constant decl |
| | | 1266 | | /// If no scope defines any constants, <see cref="MetadataTokens.LocalConstantHandle(int)"/>(1). |
| | | 1267 | | /// </param> |
| | | 1268 | | /// <param name="startOffset">Offset of the first instruction covered by the scope.</param> |
| | | 1269 | | /// <param name="length">The length (in bytes) of the scope.</param> |
| | | 1270 | | /// <remarks> |
| | | 1271 | | /// Local scopes should be added in the same order as the corresponding method definition. |
| | | 1272 | | /// Within a method they should be ordered by ascending <paramref name="startOffset"/> and then by descending <p |
| | | 1273 | | /// </remarks> |
| | | 1274 | | public LocalScopeHandle AddLocalScope(MethodDefinitionHandle method, ImportScopeHandle importScope, LocalVariabl |
| | 0 | 1275 | | { |
| | 0 | 1276 | | _localScopeTable.Add(new LocalScopeRow |
| | 0 | 1277 | | { |
| | 0 | 1278 | | Method = method.RowId, |
| | 0 | 1279 | | ImportScope = importScope.RowId, |
| | 0 | 1280 | | VariableList = variableList.RowId, |
| | 0 | 1281 | | ConstantList = constantList.RowId, |
| | 0 | 1282 | | StartOffset = startOffset, |
| | 0 | 1283 | | Length = length |
| | 0 | 1284 | | }); |
| | | 1285 | | |
| | 0 | 1286 | | return LocalScopeHandle.FromRowId(_localScopeTable.Count); |
| | 0 | 1287 | | } |
| | | 1288 | | |
| | | 1289 | | /// <summary> |
| | | 1290 | | /// Add local variable debug information. |
| | | 1291 | | /// </summary> |
| | | 1292 | | /// <param name="attributes"><see cref="LocalVariableAttributes"/></param> |
| | | 1293 | | /// <param name="index">Local variable index in the local signature (zero-based).</param> |
| | | 1294 | | /// <param name="name">Name of the variable.</param> |
| | | 1295 | | /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is greater than <see cref="ushort.Max |
| | | 1296 | | public LocalVariableHandle AddLocalVariable(LocalVariableAttributes attributes, int index, StringHandle name) |
| | 0 | 1297 | | { |
| | 0 | 1298 | | if (unchecked((uint)index) > ushort.MaxValue) |
| | 0 | 1299 | | { |
| | 0 | 1300 | | Throw.ArgumentOutOfRange(nameof(index)); |
| | | 1301 | | } |
| | | 1302 | | |
| | 0 | 1303 | | _localVariableTable.Add(new LocalVariableRow |
| | 0 | 1304 | | { |
| | 0 | 1305 | | Attributes = unchecked((ushort)attributes), |
| | 0 | 1306 | | Index = (ushort)index, |
| | 0 | 1307 | | Name = name |
| | 0 | 1308 | | }); |
| | | 1309 | | |
| | 0 | 1310 | | return LocalVariableHandle.FromRowId(_localVariableTable.Count); |
| | 0 | 1311 | | } |
| | | 1312 | | |
| | | 1313 | | /// <summary> |
| | | 1314 | | /// Add local constant debug information. |
| | | 1315 | | /// </summary> |
| | | 1316 | | /// <param name="name">Name of the variable.</param> |
| | | 1317 | | /// <param name="signature"> |
| | | 1318 | | /// LocalConstantSig blob, see https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.Metad |
| | | 1319 | | /// </param> |
| | | 1320 | | public LocalConstantHandle AddLocalConstant(StringHandle name, BlobHandle signature) |
| | 0 | 1321 | | { |
| | 0 | 1322 | | _localConstantTable.Add(new LocalConstantRow |
| | 0 | 1323 | | { |
| | 0 | 1324 | | Name = name, |
| | 0 | 1325 | | Signature = signature |
| | 0 | 1326 | | }); |
| | | 1327 | | |
| | 0 | 1328 | | return LocalConstantHandle.FromRowId(_localConstantTable.Count); |
| | 0 | 1329 | | } |
| | | 1330 | | |
| | | 1331 | | /// <summary> |
| | | 1332 | | /// Add local scope debug information. |
| | | 1333 | | /// </summary> |
| | | 1334 | | /// <param name="parentScope">Parent scope handle.</param> |
| | | 1335 | | /// <param name="imports"> |
| | | 1336 | | /// Imports blob, see https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.Metadata/specs |
| | | 1337 | | /// </param> |
| | | 1338 | | public ImportScopeHandle AddImportScope(ImportScopeHandle parentScope, BlobHandle imports) |
| | 0 | 1339 | | { |
| | 0 | 1340 | | _importScopeTable.Add(new ImportScopeRow |
| | 0 | 1341 | | { |
| | 0 | 1342 | | Parent = parentScope.RowId, |
| | 0 | 1343 | | Imports = imports |
| | 0 | 1344 | | }); |
| | | 1345 | | |
| | 0 | 1346 | | return ImportScopeHandle.FromRowId(_importScopeTable.Count); |
| | 0 | 1347 | | } |
| | | 1348 | | |
| | | 1349 | | /// <summary> |
| | | 1350 | | /// Add state machine method debug information. |
| | | 1351 | | /// </summary> |
| | | 1352 | | /// <param name="moveNextMethod">Handle of the MoveNext method of the state machine (the compiler-generated meth |
| | | 1353 | | /// <param name="kickoffMethod">Handle of the kickoff method (the user defined iterator/async method)</param> |
| | | 1354 | | /// <remarks> |
| | | 1355 | | /// Entries should be added in the same order as the corresponding MoveNext method definitions. |
| | | 1356 | | /// </remarks> |
| | | 1357 | | public void AddStateMachineMethod(MethodDefinitionHandle moveNextMethod, MethodDefinitionHandle kickoffMethod) |
| | 0 | 1358 | | { |
| | 0 | 1359 | | _stateMachineMethodTable.Add(new StateMachineMethodRow |
| | 0 | 1360 | | { |
| | 0 | 1361 | | MoveNextMethod = moveNextMethod.RowId, |
| | 0 | 1362 | | KickoffMethod = kickoffMethod.RowId |
| | 0 | 1363 | | }); |
| | 0 | 1364 | | } |
| | | 1365 | | |
| | | 1366 | | /// <summary> |
| | | 1367 | | /// Add custom debug information. |
| | | 1368 | | /// </summary> |
| | | 1369 | | /// <param name="parent"> |
| | | 1370 | | /// An entity to attach the debug information to: |
| | | 1371 | | /// <see cref="MethodDefinitionHandle"/>, |
| | | 1372 | | /// <see cref="FieldDefinitionHandle"/>, |
| | | 1373 | | /// <see cref="TypeReferenceHandle"/>, |
| | | 1374 | | /// <see cref="TypeDefinitionHandle"/>, |
| | | 1375 | | /// <see cref="ParameterHandle"/>, |
| | | 1376 | | /// <see cref="InterfaceImplementationHandle"/>, |
| | | 1377 | | /// <see cref="MemberReferenceHandle"/>, |
| | | 1378 | | /// <see cref="ModuleDefinitionHandle"/>, |
| | | 1379 | | /// <see cref="DeclarativeSecurityAttributeHandle"/>, |
| | | 1380 | | /// <see cref="PropertyDefinitionHandle"/>, |
| | | 1381 | | /// <see cref="EventDefinitionHandle"/>, |
| | | 1382 | | /// <see cref="StandaloneSignatureHandle"/>, |
| | | 1383 | | /// <see cref="ModuleReferenceHandle"/>, |
| | | 1384 | | /// <see cref="TypeSpecificationHandle"/>, |
| | | 1385 | | /// <see cref="AssemblyDefinitionHandle"/>, |
| | | 1386 | | /// <see cref="AssemblyReferenceHandle"/>, |
| | | 1387 | | /// <see cref="AssemblyFileHandle"/>, |
| | | 1388 | | /// <see cref="ExportedTypeHandle"/>, |
| | | 1389 | | /// <see cref="ManifestResourceHandle"/>, |
| | | 1390 | | /// <see cref="GenericParameterHandle"/>, |
| | | 1391 | | /// <see cref="GenericParameterConstraintHandle"/>, |
| | | 1392 | | /// <see cref="MethodSpecificationHandle"/>, |
| | | 1393 | | /// <see cref="DocumentHandle"/>, |
| | | 1394 | | /// <see cref="LocalScopeHandle"/>, |
| | | 1395 | | /// <see cref="LocalVariableHandle"/>, |
| | | 1396 | | /// <see cref="LocalConstantHandle"/> or |
| | | 1397 | | /// <see cref="ImportScopeHandle"/>. |
| | | 1398 | | /// </param> |
| | | 1399 | | /// <param name="kind">Information kind. Determines the structure of the <paramref name="value"/> blob.</param> |
| | | 1400 | | /// <param name="value">Custom debug information blob.</param> |
| | | 1401 | | /// <exception cref="ArgumentException"><paramref name="parent"/> doesn't have the expected handle kind.</except |
| | | 1402 | | /// <remarks> |
| | | 1403 | | /// Entries may be added in any order. The table is automatically sorted when serialized. |
| | | 1404 | | /// </remarks> |
| | | 1405 | | public CustomDebugInformationHandle AddCustomDebugInformation(EntityHandle parent, GuidHandle kind, BlobHandle v |
| | 0 | 1406 | | { |
| | 0 | 1407 | | _customDebugInformationTable.Add(new CustomDebugInformationRow |
| | 0 | 1408 | | { |
| | 0 | 1409 | | Parent = CodedIndex.HasCustomDebugInformation(parent), |
| | 0 | 1410 | | Kind = kind, |
| | 0 | 1411 | | Value = value |
| | 0 | 1412 | | }); |
| | | 1413 | | |
| | 0 | 1414 | | return CustomDebugInformationHandle.FromRowId(_customDebugInformationTable.Count); |
| | 0 | 1415 | | } |
| | | 1416 | | |
| | | 1417 | | #endregion |
| | | 1418 | | |
| | | 1419 | | #region Validation |
| | | 1420 | | |
| | | 1421 | | internal void ValidateOrder() |
| | 0 | 1422 | | { |
| | | 1423 | | // Certain tables are required to be sorted by a primary key, as follows: |
| | | 1424 | | // |
| | | 1425 | | // Table Keys Auto-ordered |
| | | 1426 | | // -------------------------------------------------------------------------- |
| | | 1427 | | // ClassLayout Parent No* |
| | | 1428 | | // Constant Parent Yes |
| | | 1429 | | // CustomAttribute Parent Yes |
| | | 1430 | | // DeclSecurity Parent Yes |
| | | 1431 | | // FieldLayout Field No* |
| | | 1432 | | // FieldMarshal Parent Yes |
| | | 1433 | | // FieldRVA Field No* |
| | | 1434 | | // GenericParam Owner, Number No** |
| | | 1435 | | // GenericParamConstraint Owner No** |
| | | 1436 | | // ImplMap MemberForwarded No* |
| | | 1437 | | // InterfaceImpl Class No** |
| | | 1438 | | // MethodImpl Class No* |
| | | 1439 | | // MethodSemantics Association Yes |
| | | 1440 | | // NestedClass NestedClass No* |
| | | 1441 | | // LocalScope Method, StartOffset, Length (desc) No** |
| | | 1442 | | // StateMachineMethod MoveNextMethod No* |
| | | 1443 | | // CustomDebugInformation Parent Yes |
| | | 1444 | | // |
| | | 1445 | | // Tables of entities that can't be referenced from other tables or blobs |
| | | 1446 | | // are automatically ordered during serialization and thus don't require validation. |
| | | 1447 | | // |
| | | 1448 | | // * We could potentially auto-order these. These tables are adding extra (optional) |
| | | 1449 | | // information to a primary entity (TypeDef, FiledDef, etc.) and are thus easily emitted |
| | | 1450 | | // in the same order as the parent entity. Hence they would usually be ordered already and |
| | | 1451 | | // it would be extra overhead to order them. Let's just required them ordered. |
| | | 1452 | | // |
| | | 1453 | | // ** We can't easily automatically order these since they represent entities that can be referenced |
| | | 1454 | | // by other tables/blobs (e.g. CustomAttribute and CustomDebugInformation). Ordering these tables |
| | | 1455 | | // would require updating all references. |
| | | 1456 | | |
| | 0 | 1457 | | ValidateClassLayoutTable(); |
| | 0 | 1458 | | ValidateFieldLayoutTable(); |
| | 0 | 1459 | | ValidateFieldRvaTable(); |
| | 0 | 1460 | | ValidateGenericParamTable(); |
| | 0 | 1461 | | ValidateGenericParamConstaintTable(); |
| | 0 | 1462 | | ValidateImplMapTable(); |
| | 0 | 1463 | | ValidateInterfaceImplTable(); |
| | 0 | 1464 | | ValidateMethodImplTable(); |
| | 0 | 1465 | | ValidateNestedClassTable(); |
| | 0 | 1466 | | ValidateLocalScopeTable(); |
| | 0 | 1467 | | ValidateStateMachineMethodTable(); |
| | 0 | 1468 | | } |
| | | 1469 | | |
| | | 1470 | | private void ValidateClassLayoutTable() |
| | 0 | 1471 | | { |
| | 0 | 1472 | | for (int i = 1; i < _classLayoutTable.Count; i++) |
| | 0 | 1473 | | { |
| | 0 | 1474 | | if (_classLayoutTable[i - 1].Parent >= _classLayoutTable[i].Parent) |
| | 0 | 1475 | | { |
| | 0 | 1476 | | Throw.InvalidOperation_TableNotSorted(TableIndex.ClassLayout); |
| | | 1477 | | } |
| | 0 | 1478 | | } |
| | 0 | 1479 | | } |
| | | 1480 | | |
| | | 1481 | | private void ValidateFieldLayoutTable() |
| | 0 | 1482 | | { |
| | 0 | 1483 | | for (int i = 1; i < _fieldLayoutTable.Count; i++) |
| | 0 | 1484 | | { |
| | 0 | 1485 | | if (_fieldLayoutTable[i - 1].Field >= _fieldLayoutTable[i].Field) |
| | 0 | 1486 | | { |
| | 0 | 1487 | | Throw.InvalidOperation_TableNotSorted(TableIndex.FieldLayout); |
| | | 1488 | | } |
| | 0 | 1489 | | } |
| | 0 | 1490 | | } |
| | | 1491 | | |
| | | 1492 | | private void ValidateFieldRvaTable() |
| | 0 | 1493 | | { |
| | 0 | 1494 | | for (int i = 1; i < _fieldRvaTable.Count; i++) |
| | 0 | 1495 | | { |
| | | 1496 | | // Spec: each row in the FieldRVA table is an extension to exactly one row in the Field table |
| | 0 | 1497 | | if (_fieldRvaTable[i - 1].Field >= _fieldRvaTable[i].Field) |
| | 0 | 1498 | | { |
| | 0 | 1499 | | Throw.InvalidOperation_TableNotSorted(TableIndex.FieldRva); |
| | | 1500 | | } |
| | 0 | 1501 | | } |
| | 0 | 1502 | | } |
| | | 1503 | | |
| | | 1504 | | private void ValidateGenericParamTable() |
| | 0 | 1505 | | { |
| | 0 | 1506 | | if (_genericParamTable.Count == 0) |
| | 0 | 1507 | | { |
| | 0 | 1508 | | return; |
| | | 1509 | | } |
| | | 1510 | | |
| | 0 | 1511 | | GenericParamRow current, previous = _genericParamTable[0]; |
| | 0 | 1512 | | for (int i = 1; i < _genericParamTable.Count; i++, previous = current) |
| | 0 | 1513 | | { |
| | 0 | 1514 | | current = _genericParamTable[i]; |
| | | 1515 | | |
| | 0 | 1516 | | if (current.Owner > previous.Owner) |
| | 0 | 1517 | | { |
| | 0 | 1518 | | continue; |
| | | 1519 | | } |
| | | 1520 | | |
| | 0 | 1521 | | if (previous.Owner == current.Owner && current.Number > previous.Number) |
| | 0 | 1522 | | { |
| | 0 | 1523 | | continue; |
| | | 1524 | | } |
| | | 1525 | | |
| | 0 | 1526 | | Throw.InvalidOperation_TableNotSorted(TableIndex.GenericParam); |
| | | 1527 | | } |
| | 0 | 1528 | | } |
| | | 1529 | | |
| | | 1530 | | private void ValidateGenericParamConstaintTable() |
| | 0 | 1531 | | { |
| | 0 | 1532 | | for (int i = 1; i < _genericParamConstraintTable.Count; i++) |
| | 0 | 1533 | | { |
| | 0 | 1534 | | if (_genericParamConstraintTable[i - 1].Owner > _genericParamConstraintTable[i].Owner) |
| | 0 | 1535 | | { |
| | 0 | 1536 | | Throw.InvalidOperation_TableNotSorted(TableIndex.GenericParamConstraint); |
| | | 1537 | | } |
| | 0 | 1538 | | } |
| | 0 | 1539 | | } |
| | | 1540 | | |
| | | 1541 | | private void ValidateImplMapTable() |
| | 0 | 1542 | | { |
| | 0 | 1543 | | for (int i = 1; i < _implMapTable.Count; i++) |
| | 0 | 1544 | | { |
| | 0 | 1545 | | if (_implMapTable[i - 1].MemberForwarded >= _implMapTable[i].MemberForwarded) |
| | 0 | 1546 | | { |
| | 0 | 1547 | | Throw.InvalidOperation_TableNotSorted(TableIndex.ImplMap); |
| | | 1548 | | } |
| | 0 | 1549 | | } |
| | 0 | 1550 | | } |
| | | 1551 | | |
| | | 1552 | | private void ValidateInterfaceImplTable() |
| | 0 | 1553 | | { |
| | 0 | 1554 | | for (int i = 1; i < _interfaceImplTable.Count; i++) |
| | 0 | 1555 | | { |
| | 0 | 1556 | | if (_interfaceImplTable[i - 1].Class > _interfaceImplTable[i].Class) |
| | 0 | 1557 | | { |
| | 0 | 1558 | | Throw.InvalidOperation_TableNotSorted(TableIndex.InterfaceImpl); |
| | | 1559 | | } |
| | 0 | 1560 | | } |
| | 0 | 1561 | | } |
| | | 1562 | | |
| | | 1563 | | private void ValidateMethodImplTable() |
| | 0 | 1564 | | { |
| | 0 | 1565 | | for (int i = 1; i < _methodImplTable.Count; i++) |
| | 0 | 1566 | | { |
| | 0 | 1567 | | if (_methodImplTable[i - 1].Class > _methodImplTable[i].Class) |
| | 0 | 1568 | | { |
| | 0 | 1569 | | Throw.InvalidOperation_TableNotSorted(TableIndex.MethodImpl); |
| | | 1570 | | } |
| | 0 | 1571 | | } |
| | 0 | 1572 | | } |
| | | 1573 | | |
| | | 1574 | | private void ValidateNestedClassTable() |
| | 0 | 1575 | | { |
| | 0 | 1576 | | for (int i = 1; i < _nestedClassTable.Count; i++) |
| | 0 | 1577 | | { |
| | 0 | 1578 | | if (_nestedClassTable[i - 1].NestedClass >= _nestedClassTable[i].NestedClass) |
| | 0 | 1579 | | { |
| | 0 | 1580 | | Throw.InvalidOperation_TableNotSorted(TableIndex.NestedClass); |
| | | 1581 | | } |
| | 0 | 1582 | | } |
| | 0 | 1583 | | } |
| | | 1584 | | |
| | | 1585 | | private void ValidateLocalScopeTable() |
| | 0 | 1586 | | { |
| | 0 | 1587 | | if (_localScopeTable.Count == 0) |
| | 0 | 1588 | | { |
| | 0 | 1589 | | return; |
| | | 1590 | | } |
| | | 1591 | | |
| | | 1592 | | // Spec: The table is required to be sorted first by Method in ascending order, |
| | | 1593 | | // then by StartOffset in ascending order, then by Length in descending order. |
| | 0 | 1594 | | LocalScopeRow current, previous = _localScopeTable[0]; |
| | 0 | 1595 | | for (int i = 1; i < _localScopeTable.Count; i++, previous = current) |
| | 0 | 1596 | | { |
| | 0 | 1597 | | current = _localScopeTable[i]; |
| | | 1598 | | |
| | 0 | 1599 | | if (current.Method > previous.Method) |
| | 0 | 1600 | | { |
| | 0 | 1601 | | continue; |
| | | 1602 | | } |
| | | 1603 | | |
| | 0 | 1604 | | if (current.Method == previous.Method) |
| | 0 | 1605 | | { |
| | 0 | 1606 | | if (current.StartOffset > previous.StartOffset) |
| | 0 | 1607 | | { |
| | 0 | 1608 | | continue; |
| | | 1609 | | } |
| | | 1610 | | |
| | 0 | 1611 | | if (current.StartOffset == previous.StartOffset && previous.Length >= current.Length) |
| | 0 | 1612 | | { |
| | 0 | 1613 | | continue; |
| | | 1614 | | } |
| | 0 | 1615 | | } |
| | | 1616 | | |
| | 0 | 1617 | | Throw.InvalidOperation_TableNotSorted(TableIndex.LocalScope); |
| | | 1618 | | } |
| | 0 | 1619 | | } |
| | | 1620 | | |
| | | 1621 | | private void ValidateStateMachineMethodTable() |
| | 0 | 1622 | | { |
| | 0 | 1623 | | for (int i = 1; i < _stateMachineMethodTable.Count; i++) |
| | 0 | 1624 | | { |
| | 0 | 1625 | | if (_stateMachineMethodTable[i - 1].MoveNextMethod >= _stateMachineMethodTable[i].MoveNextMethod) |
| | 0 | 1626 | | { |
| | 0 | 1627 | | Throw.InvalidOperation_TableNotSorted(TableIndex.StateMachineMethod); |
| | | 1628 | | } |
| | 0 | 1629 | | } |
| | 0 | 1630 | | } |
| | | 1631 | | |
| | | 1632 | | #endregion |
| | | 1633 | | |
| | | 1634 | | #region Serialization |
| | | 1635 | | |
| | | 1636 | | internal void SerializeMetadataTables( |
| | | 1637 | | BlobBuilder writer, |
| | | 1638 | | MetadataSizes metadataSizes, |
| | | 1639 | | ImmutableArray<int> stringMap, |
| | | 1640 | | int methodBodyStreamRva, |
| | | 1641 | | int mappedFieldDataStreamRva) |
| | 0 | 1642 | | { |
| | 0 | 1643 | | int startPosition = writer.Count; |
| | | 1644 | | |
| | 0 | 1645 | | SerializeTablesHeader(writer, metadataSizes); |
| | | 1646 | | |
| | 0 | 1647 | | if (metadataSizes.IsPresent(TableIndex.Module)) |
| | 0 | 1648 | | { |
| | 0 | 1649 | | SerializeModuleTable(writer, stringMap, metadataSizes); |
| | 0 | 1650 | | } |
| | | 1651 | | |
| | 0 | 1652 | | if (metadataSizes.IsPresent(TableIndex.TypeRef)) |
| | 0 | 1653 | | { |
| | 0 | 1654 | | SerializeTypeRefTable(writer, stringMap, metadataSizes); |
| | 0 | 1655 | | } |
| | | 1656 | | |
| | 0 | 1657 | | if (metadataSizes.IsPresent(TableIndex.TypeDef)) |
| | 0 | 1658 | | { |
| | 0 | 1659 | | SerializeTypeDefTable(writer, stringMap, metadataSizes); |
| | 0 | 1660 | | } |
| | | 1661 | | |
| | 0 | 1662 | | if (metadataSizes.IsPresent(TableIndex.Field)) |
| | 0 | 1663 | | { |
| | 0 | 1664 | | SerializeFieldTable(writer, stringMap, metadataSizes); |
| | 0 | 1665 | | } |
| | | 1666 | | |
| | 0 | 1667 | | if (metadataSizes.IsPresent(TableIndex.MethodDef)) |
| | 0 | 1668 | | { |
| | 0 | 1669 | | SerializeMethodDefTable(writer, stringMap, metadataSizes, methodBodyStreamRva); |
| | 0 | 1670 | | } |
| | | 1671 | | |
| | 0 | 1672 | | if (metadataSizes.IsPresent(TableIndex.Param)) |
| | 0 | 1673 | | { |
| | 0 | 1674 | | SerializeParamTable(writer, stringMap, metadataSizes); |
| | 0 | 1675 | | } |
| | | 1676 | | |
| | 0 | 1677 | | if (metadataSizes.IsPresent(TableIndex.InterfaceImpl)) |
| | 0 | 1678 | | { |
| | 0 | 1679 | | SerializeInterfaceImplTable(writer, metadataSizes); |
| | 0 | 1680 | | } |
| | | 1681 | | |
| | 0 | 1682 | | if (metadataSizes.IsPresent(TableIndex.MemberRef)) |
| | 0 | 1683 | | { |
| | 0 | 1684 | | SerializeMemberRefTable(writer, stringMap, metadataSizes); |
| | 0 | 1685 | | } |
| | | 1686 | | |
| | 0 | 1687 | | if (metadataSizes.IsPresent(TableIndex.Constant)) |
| | 0 | 1688 | | { |
| | 0 | 1689 | | SerializeConstantTable(writer, metadataSizes); |
| | 0 | 1690 | | } |
| | | 1691 | | |
| | 0 | 1692 | | if (metadataSizes.IsPresent(TableIndex.CustomAttribute)) |
| | 0 | 1693 | | { |
| | 0 | 1694 | | SerializeCustomAttributeTable(writer, metadataSizes); |
| | 0 | 1695 | | } |
| | | 1696 | | |
| | 0 | 1697 | | if (metadataSizes.IsPresent(TableIndex.FieldMarshal)) |
| | 0 | 1698 | | { |
| | 0 | 1699 | | SerializeFieldMarshalTable(writer, metadataSizes); |
| | 0 | 1700 | | } |
| | | 1701 | | |
| | 0 | 1702 | | if (metadataSizes.IsPresent(TableIndex.DeclSecurity)) |
| | 0 | 1703 | | { |
| | 0 | 1704 | | SerializeDeclSecurityTable(writer, metadataSizes); |
| | 0 | 1705 | | } |
| | | 1706 | | |
| | 0 | 1707 | | if (metadataSizes.IsPresent(TableIndex.ClassLayout)) |
| | 0 | 1708 | | { |
| | 0 | 1709 | | SerializeClassLayoutTable(writer, metadataSizes); |
| | 0 | 1710 | | } |
| | | 1711 | | |
| | 0 | 1712 | | if (metadataSizes.IsPresent(TableIndex.FieldLayout)) |
| | 0 | 1713 | | { |
| | 0 | 1714 | | SerializeFieldLayoutTable(writer, metadataSizes); |
| | 0 | 1715 | | } |
| | | 1716 | | |
| | 0 | 1717 | | if (metadataSizes.IsPresent(TableIndex.StandAloneSig)) |
| | 0 | 1718 | | { |
| | 0 | 1719 | | SerializeStandAloneSigTable(writer, metadataSizes); |
| | 0 | 1720 | | } |
| | | 1721 | | |
| | 0 | 1722 | | if (metadataSizes.IsPresent(TableIndex.EventMap)) |
| | 0 | 1723 | | { |
| | 0 | 1724 | | SerializeEventMapTable(writer, metadataSizes); |
| | 0 | 1725 | | } |
| | | 1726 | | |
| | 0 | 1727 | | if (metadataSizes.IsPresent(TableIndex.Event)) |
| | 0 | 1728 | | { |
| | 0 | 1729 | | SerializeEventTable(writer, stringMap, metadataSizes); |
| | 0 | 1730 | | } |
| | | 1731 | | |
| | 0 | 1732 | | if (metadataSizes.IsPresent(TableIndex.PropertyMap)) |
| | 0 | 1733 | | { |
| | 0 | 1734 | | SerializePropertyMapTable(writer, metadataSizes); |
| | 0 | 1735 | | } |
| | | 1736 | | |
| | 0 | 1737 | | if (metadataSizes.IsPresent(TableIndex.Property)) |
| | 0 | 1738 | | { |
| | 0 | 1739 | | SerializePropertyTable(writer, stringMap, metadataSizes); |
| | 0 | 1740 | | } |
| | | 1741 | | |
| | 0 | 1742 | | if (metadataSizes.IsPresent(TableIndex.MethodSemantics)) |
| | 0 | 1743 | | { |
| | 0 | 1744 | | SerializeMethodSemanticsTable(writer, metadataSizes); |
| | 0 | 1745 | | } |
| | | 1746 | | |
| | 0 | 1747 | | if (metadataSizes.IsPresent(TableIndex.MethodImpl)) |
| | 0 | 1748 | | { |
| | 0 | 1749 | | SerializeMethodImplTable(writer, metadataSizes); |
| | 0 | 1750 | | } |
| | | 1751 | | |
| | 0 | 1752 | | if (metadataSizes.IsPresent(TableIndex.ModuleRef)) |
| | 0 | 1753 | | { |
| | 0 | 1754 | | SerializeModuleRefTable(writer, stringMap, metadataSizes); |
| | 0 | 1755 | | } |
| | | 1756 | | |
| | 0 | 1757 | | if (metadataSizes.IsPresent(TableIndex.TypeSpec)) |
| | 0 | 1758 | | { |
| | 0 | 1759 | | SerializeTypeSpecTable(writer, metadataSizes); |
| | 0 | 1760 | | } |
| | | 1761 | | |
| | 0 | 1762 | | if (metadataSizes.IsPresent(TableIndex.ImplMap)) |
| | 0 | 1763 | | { |
| | 0 | 1764 | | SerializeImplMapTable(writer, stringMap, metadataSizes); |
| | 0 | 1765 | | } |
| | | 1766 | | |
| | 0 | 1767 | | if (metadataSizes.IsPresent(TableIndex.FieldRva)) |
| | 0 | 1768 | | { |
| | 0 | 1769 | | SerializeFieldRvaTable(writer, metadataSizes, mappedFieldDataStreamRva); |
| | 0 | 1770 | | } |
| | | 1771 | | |
| | 0 | 1772 | | if (metadataSizes.IsPresent(TableIndex.EncLog)) |
| | 0 | 1773 | | { |
| | 0 | 1774 | | SerializeEncLogTable(writer); |
| | 0 | 1775 | | } |
| | | 1776 | | |
| | 0 | 1777 | | if (metadataSizes.IsPresent(TableIndex.EncMap)) |
| | 0 | 1778 | | { |
| | 0 | 1779 | | SerializeEncMapTable(writer); |
| | 0 | 1780 | | } |
| | | 1781 | | |
| | 0 | 1782 | | if (metadataSizes.IsPresent(TableIndex.Assembly)) |
| | 0 | 1783 | | { |
| | 0 | 1784 | | SerializeAssemblyTable(writer, stringMap, metadataSizes); |
| | 0 | 1785 | | } |
| | | 1786 | | |
| | 0 | 1787 | | if (metadataSizes.IsPresent(TableIndex.AssemblyRef)) |
| | 0 | 1788 | | { |
| | 0 | 1789 | | SerializeAssemblyRefTable(writer, stringMap, metadataSizes); |
| | 0 | 1790 | | } |
| | | 1791 | | |
| | 0 | 1792 | | if (metadataSizes.IsPresent(TableIndex.File)) |
| | 0 | 1793 | | { |
| | 0 | 1794 | | SerializeFileTable(writer, stringMap, metadataSizes); |
| | 0 | 1795 | | } |
| | | 1796 | | |
| | 0 | 1797 | | if (metadataSizes.IsPresent(TableIndex.ExportedType)) |
| | 0 | 1798 | | { |
| | 0 | 1799 | | SerializeExportedTypeTable(writer, stringMap, metadataSizes); |
| | 0 | 1800 | | } |
| | | 1801 | | |
| | 0 | 1802 | | if (metadataSizes.IsPresent(TableIndex.ManifestResource)) |
| | 0 | 1803 | | { |
| | 0 | 1804 | | SerializeManifestResourceTable(writer, stringMap, metadataSizes); |
| | 0 | 1805 | | } |
| | | 1806 | | |
| | 0 | 1807 | | if (metadataSizes.IsPresent(TableIndex.NestedClass)) |
| | 0 | 1808 | | { |
| | 0 | 1809 | | SerializeNestedClassTable(writer, metadataSizes); |
| | 0 | 1810 | | } |
| | | 1811 | | |
| | 0 | 1812 | | if (metadataSizes.IsPresent(TableIndex.GenericParam)) |
| | 0 | 1813 | | { |
| | 0 | 1814 | | SerializeGenericParamTable(writer, stringMap, metadataSizes); |
| | 0 | 1815 | | } |
| | | 1816 | | |
| | 0 | 1817 | | if (metadataSizes.IsPresent(TableIndex.MethodSpec)) |
| | 0 | 1818 | | { |
| | 0 | 1819 | | SerializeMethodSpecTable(writer, metadataSizes); |
| | 0 | 1820 | | } |
| | | 1821 | | |
| | 0 | 1822 | | if (metadataSizes.IsPresent(TableIndex.GenericParamConstraint)) |
| | 0 | 1823 | | { |
| | 0 | 1824 | | SerializeGenericParamConstraintTable(writer, metadataSizes); |
| | 0 | 1825 | | } |
| | | 1826 | | |
| | | 1827 | | // debug tables |
| | 0 | 1828 | | if (metadataSizes.IsPresent(TableIndex.Document)) |
| | 0 | 1829 | | { |
| | 0 | 1830 | | SerializeDocumentTable(writer, metadataSizes); |
| | 0 | 1831 | | } |
| | | 1832 | | |
| | 0 | 1833 | | if (metadataSizes.IsPresent(TableIndex.MethodDebugInformation)) |
| | 0 | 1834 | | { |
| | 0 | 1835 | | SerializeMethodDebugInformationTable(writer, metadataSizes); |
| | 0 | 1836 | | } |
| | | 1837 | | |
| | 0 | 1838 | | if (metadataSizes.IsPresent(TableIndex.LocalScope)) |
| | 0 | 1839 | | { |
| | 0 | 1840 | | SerializeLocalScopeTable(writer, metadataSizes); |
| | 0 | 1841 | | } |
| | | 1842 | | |
| | 0 | 1843 | | if (metadataSizes.IsPresent(TableIndex.LocalVariable)) |
| | 0 | 1844 | | { |
| | 0 | 1845 | | SerializeLocalVariableTable(writer, stringMap, metadataSizes); |
| | 0 | 1846 | | } |
| | | 1847 | | |
| | 0 | 1848 | | if (metadataSizes.IsPresent(TableIndex.LocalConstant)) |
| | 0 | 1849 | | { |
| | 0 | 1850 | | SerializeLocalConstantTable(writer, stringMap, metadataSizes); |
| | 0 | 1851 | | } |
| | | 1852 | | |
| | 0 | 1853 | | if (metadataSizes.IsPresent(TableIndex.ImportScope)) |
| | 0 | 1854 | | { |
| | 0 | 1855 | | SerializeImportScopeTable(writer, metadataSizes); |
| | 0 | 1856 | | } |
| | | 1857 | | |
| | 0 | 1858 | | if (metadataSizes.IsPresent(TableIndex.StateMachineMethod)) |
| | 0 | 1859 | | { |
| | 0 | 1860 | | SerializeStateMachineMethodTable(writer, metadataSizes); |
| | 0 | 1861 | | } |
| | | 1862 | | |
| | 0 | 1863 | | if (metadataSizes.IsPresent(TableIndex.CustomDebugInformation)) |
| | 0 | 1864 | | { |
| | 0 | 1865 | | SerializeCustomDebugInformationTable(writer, metadataSizes); |
| | 0 | 1866 | | } |
| | | 1867 | | |
| | 0 | 1868 | | writer.WriteByte(0); |
| | 0 | 1869 | | writer.Align(4); |
| | | 1870 | | |
| | 0 | 1871 | | int endPosition = writer.Count; |
| | 0 | 1872 | | Debug.Assert(metadataSizes.MetadataTableStreamSize == endPosition - startPosition); |
| | 0 | 1873 | | } |
| | | 1874 | | |
| | | 1875 | | private static void SerializeTablesHeader(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 1876 | | { |
| | 0 | 1877 | | int startPosition = writer.Count; |
| | | 1878 | | |
| | 0 | 1879 | | HeapSizeFlag heapSizes = 0; |
| | 0 | 1880 | | if (!metadataSizes.StringReferenceIsSmall) |
| | 0 | 1881 | | { |
| | 0 | 1882 | | heapSizes |= HeapSizeFlag.StringHeapLarge; |
| | 0 | 1883 | | } |
| | | 1884 | | |
| | 0 | 1885 | | if (!metadataSizes.GuidReferenceIsSmall) |
| | 0 | 1886 | | { |
| | 0 | 1887 | | heapSizes |= HeapSizeFlag.GuidHeapLarge; |
| | 0 | 1888 | | } |
| | | 1889 | | |
| | 0 | 1890 | | if (!metadataSizes.BlobReferenceIsSmall) |
| | 0 | 1891 | | { |
| | 0 | 1892 | | heapSizes |= HeapSizeFlag.BlobHeapLarge; |
| | 0 | 1893 | | } |
| | | 1894 | | |
| | 0 | 1895 | | if (metadataSizes.IsEncDelta) |
| | 0 | 1896 | | { |
| | 0 | 1897 | | heapSizes |= HeapSizeFlag.EncDeltas | HeapSizeFlag.DeletedMarks; |
| | 0 | 1898 | | } |
| | | 1899 | | |
| | | 1900 | | // Custom Attribute table is not sorted in delta metadata: |
| | 0 | 1901 | | ulong sortedTables = |
| | 0 | 1902 | | metadataSizes.IsEncDelta ? MetadataSizes.SortedTypeSystemTables & ~(1UL << (int)TableIndex.CustomAttribu |
| | 0 | 1903 | | metadataSizes.IsStandaloneDebugMetadata ? 0 : |
| | 0 | 1904 | | MetadataSizes.SortedTypeSystemTables; |
| | | 1905 | | |
| | | 1906 | | // Consider filtering out type system tables that are not present: |
| | 0 | 1907 | | sortedTables |= metadataSizes.PresentTablesMask & MetadataSizes.SortedDebugTables; |
| | | 1908 | | |
| | 0 | 1909 | | writer.WriteUInt32(0); // reserved |
| | 0 | 1910 | | writer.WriteByte(MetadataFormatMajorVersion); |
| | 0 | 1911 | | writer.WriteByte(MetadataFormatMinorVersion); |
| | 0 | 1912 | | writer.WriteByte((byte)heapSizes); |
| | 0 | 1913 | | writer.WriteByte(1); // reserved |
| | 0 | 1914 | | writer.WriteUInt64(metadataSizes.PresentTablesMask); |
| | 0 | 1915 | | writer.WriteUInt64(sortedTables); |
| | 0 | 1916 | | MetadataWriterUtilities.SerializeRowCounts(writer, metadataSizes.RowCounts); |
| | | 1917 | | |
| | 0 | 1918 | | int endPosition = writer.Count; |
| | 0 | 1919 | | Debug.Assert(metadataSizes.CalculateTableStreamHeaderSize() == endPosition - startPosition); |
| | 0 | 1920 | | } |
| | | 1921 | | |
| | | 1922 | | // internal for testing |
| | | 1923 | | internal void SerializeModuleTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSize |
| | 0 | 1924 | | { |
| | 0 | 1925 | | if (_moduleRow.HasValue) |
| | 0 | 1926 | | { |
| | 0 | 1927 | | writer.WriteUInt16(_moduleRow.Value.Generation); |
| | 0 | 1928 | | writer.WriteReference(SerializeHandle(stringMap, _moduleRow.Value.Name), metadataSizes.StringReferenceIs |
| | 0 | 1929 | | writer.WriteReference(SerializeHandle(_moduleRow.Value.ModuleVersionId), metadataSizes.GuidReferenceIsSm |
| | 0 | 1930 | | writer.WriteReference(SerializeHandle(_moduleRow.Value.EncId), metadataSizes.GuidReferenceIsSmall); |
| | 0 | 1931 | | writer.WriteReference(SerializeHandle(_moduleRow.Value.EncBaseId), metadataSizes.GuidReferenceIsSmall); |
| | 0 | 1932 | | } |
| | 0 | 1933 | | } |
| | | 1934 | | |
| | | 1935 | | private void SerializeEncLogTable(BlobBuilder writer) |
| | 0 | 1936 | | { |
| | 0 | 1937 | | foreach (EncLogRow encLog in _encLogTable) |
| | 0 | 1938 | | { |
| | 0 | 1939 | | writer.WriteInt32(encLog.Token); |
| | 0 | 1940 | | writer.WriteUInt32(encLog.FuncCode); |
| | 0 | 1941 | | } |
| | 0 | 1942 | | } |
| | | 1943 | | |
| | | 1944 | | private void SerializeEncMapTable(BlobBuilder writer) |
| | 0 | 1945 | | { |
| | 0 | 1946 | | foreach (EncMapRow encMap in _encMapTable) |
| | 0 | 1947 | | { |
| | 0 | 1948 | | writer.WriteInt32(encMap.Token); |
| | 0 | 1949 | | } |
| | 0 | 1950 | | } |
| | | 1951 | | |
| | | 1952 | | private void SerializeTypeRefTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSize |
| | 0 | 1953 | | { |
| | 0 | 1954 | | foreach (TypeRefRow typeRef in _typeRefTable) |
| | 0 | 1955 | | { |
| | 0 | 1956 | | writer.WriteReference(typeRef.ResolutionScope, metadataSizes.ResolutionScopeCodedIndexIsSmall); |
| | 0 | 1957 | | writer.WriteReference(SerializeHandle(stringMap, typeRef.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 1958 | | writer.WriteReference(SerializeHandle(stringMap, typeRef.Namespace), metadataSizes.StringReferenceIsSmal |
| | 0 | 1959 | | } |
| | 0 | 1960 | | } |
| | | 1961 | | |
| | | 1962 | | private void SerializeTypeDefTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSize |
| | 0 | 1963 | | { |
| | 0 | 1964 | | foreach (TypeDefRow typeDef in _typeDefTable) |
| | 0 | 1965 | | { |
| | 0 | 1966 | | writer.WriteUInt32(typeDef.Flags); |
| | 0 | 1967 | | writer.WriteReference(SerializeHandle(stringMap, typeDef.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 1968 | | writer.WriteReference(SerializeHandle(stringMap, typeDef.Namespace), metadataSizes.StringReferenceIsSmal |
| | 0 | 1969 | | writer.WriteReference(typeDef.Extends, metadataSizes.TypeDefOrRefCodedIndexIsSmall); |
| | 0 | 1970 | | writer.WriteReference(typeDef.FieldList, metadataSizes.FieldDefReferenceIsSmall); |
| | 0 | 1971 | | writer.WriteReference(typeDef.MethodList, metadataSizes.MethodDefReferenceIsSmall); |
| | 0 | 1972 | | } |
| | 0 | 1973 | | } |
| | | 1974 | | |
| | | 1975 | | private void SerializeFieldTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSizes) |
| | 0 | 1976 | | { |
| | 0 | 1977 | | foreach (FieldDefRow fieldDef in _fieldTable) |
| | 0 | 1978 | | { |
| | 0 | 1979 | | writer.WriteUInt16(fieldDef.Flags); |
| | 0 | 1980 | | writer.WriteReference(SerializeHandle(stringMap, fieldDef.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 1981 | | writer.WriteReference(SerializeHandle(fieldDef.Signature), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 1982 | | } |
| | 0 | 1983 | | } |
| | | 1984 | | |
| | | 1985 | | private void SerializeMethodDefTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSi |
| | 0 | 1986 | | { |
| | 0 | 1987 | | foreach (MethodRow method in _methodDefTable) |
| | 0 | 1988 | | { |
| | 0 | 1989 | | if (method.BodyOffset == -1) |
| | 0 | 1990 | | { |
| | 0 | 1991 | | writer.WriteUInt32(0); |
| | 0 | 1992 | | } |
| | | 1993 | | else |
| | 0 | 1994 | | { |
| | 0 | 1995 | | writer.WriteInt32(methodBodyStreamRva + method.BodyOffset); |
| | 0 | 1996 | | } |
| | | 1997 | | |
| | 0 | 1998 | | writer.WriteUInt16(method.ImplFlags); |
| | 0 | 1999 | | writer.WriteUInt16(method.Flags); |
| | 0 | 2000 | | writer.WriteReference(SerializeHandle(stringMap, method.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 2001 | | writer.WriteReference(SerializeHandle(method.Signature), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2002 | | writer.WriteReference(method.ParamList, metadataSizes.ParameterReferenceIsSmall); |
| | 0 | 2003 | | } |
| | 0 | 2004 | | } |
| | | 2005 | | |
| | | 2006 | | private void SerializeParamTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSizes) |
| | 0 | 2007 | | { |
| | 0 | 2008 | | foreach (ParamRow param in _paramTable) |
| | 0 | 2009 | | { |
| | 0 | 2010 | | writer.WriteUInt16(param.Flags); |
| | 0 | 2011 | | writer.WriteUInt16(param.Sequence); |
| | 0 | 2012 | | writer.WriteReference(SerializeHandle(stringMap, param.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 2013 | | } |
| | 0 | 2014 | | } |
| | | 2015 | | |
| | | 2016 | | private void SerializeInterfaceImplTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2017 | | { |
| | | 2018 | | // TODO (bug https://github.com/dotnet/roslyn/issues/3905): |
| | | 2019 | | // We should sort the table by Class and then by Interface. |
| | 0 | 2020 | | foreach (InterfaceImplRow interfaceImpl in _interfaceImplTable) |
| | 0 | 2021 | | { |
| | 0 | 2022 | | writer.WriteReference(interfaceImpl.Class, metadataSizes.TypeDefReferenceIsSmall); |
| | 0 | 2023 | | writer.WriteReference(interfaceImpl.Interface, metadataSizes.TypeDefOrRefCodedIndexIsSmall); |
| | 0 | 2024 | | } |
| | 0 | 2025 | | } |
| | | 2026 | | |
| | | 2027 | | private void SerializeMemberRefTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSi |
| | 0 | 2028 | | { |
| | 0 | 2029 | | foreach (MemberRefRow memberRef in _memberRefTable) |
| | 0 | 2030 | | { |
| | 0 | 2031 | | writer.WriteReference(memberRef.Class, metadataSizes.MemberRefParentCodedIndexIsSmall); |
| | 0 | 2032 | | writer.WriteReference(SerializeHandle(stringMap, memberRef.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 2033 | | writer.WriteReference(SerializeHandle(memberRef.Signature), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2034 | | } |
| | 0 | 2035 | | } |
| | | 2036 | | |
| | | 2037 | | private void SerializeConstantTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2038 | | { |
| | | 2039 | | // Note: we can sort the table at this point since no other table can reference its rows via RowId or CodedI |
| | 0 | 2040 | | var ordered = _constantTableNeedsSorting ? _constantTable.OrderBy((x, y) => x.Parent - y.Parent) : _constant |
| | | 2041 | | |
| | 0 | 2042 | | foreach (ConstantRow constant in ordered) |
| | 0 | 2043 | | { |
| | 0 | 2044 | | writer.WriteByte(constant.Type); |
| | 0 | 2045 | | writer.WriteByte(0); |
| | 0 | 2046 | | writer.WriteReference(constant.Parent, metadataSizes.HasConstantCodedIndexIsSmall); |
| | 0 | 2047 | | writer.WriteReference(SerializeHandle(constant.Value), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2048 | | } |
| | 0 | 2049 | | } |
| | | 2050 | | |
| | | 2051 | | private void SerializeCustomAttributeTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2052 | | { |
| | | 2053 | | // Note: we can sort the table at this point since no other table can reference its rows via RowId or CodedI |
| | | 2054 | | // OrderBy performs a stable sort, so multiple attributes with the same parent will be sorted in the order t |
| | | 2055 | | // Avoid sorting the table when emitting EnC delta. Deleted attributes are represented in the table as rows |
| | | 2056 | | // Sorting the table would move them to the beginning of the table and break mapping specified in EncMap tab |
| | 0 | 2057 | | var ordered = _customAttributeTableNeedsSorting && !metadataSizes.IsEncDelta ? _customAttributeTable.OrderBy |
| | | 2058 | | |
| | 0 | 2059 | | foreach (CustomAttributeRow customAttribute in ordered) |
| | 0 | 2060 | | { |
| | 0 | 2061 | | writer.WriteReference(customAttribute.Parent, metadataSizes.HasCustomAttributeCodedIndexIsSmall); |
| | 0 | 2062 | | writer.WriteReference(customAttribute.Type, metadataSizes.CustomAttributeTypeCodedIndexIsSmall); |
| | 0 | 2063 | | writer.WriteReference(SerializeHandle(customAttribute.Value), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2064 | | } |
| | 0 | 2065 | | } |
| | | 2066 | | |
| | | 2067 | | private void SerializeFieldMarshalTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2068 | | { |
| | | 2069 | | // Note: we can sort the table at this point since no other table can reference its rows via RowId or CodedI |
| | 0 | 2070 | | var ordered = _fieldMarshalTableNeedsSorting ? _fieldMarshalTable.OrderBy((x, y) => x.Parent - y.Parent) : _ |
| | | 2071 | | |
| | 0 | 2072 | | foreach (FieldMarshalRow fieldMarshal in ordered) |
| | 0 | 2073 | | { |
| | 0 | 2074 | | writer.WriteReference(fieldMarshal.Parent, metadataSizes.HasFieldMarshalCodedIndexIsSmall); |
| | 0 | 2075 | | writer.WriteReference(SerializeHandle(fieldMarshal.NativeType), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2076 | | } |
| | 0 | 2077 | | } |
| | | 2078 | | |
| | | 2079 | | private void SerializeDeclSecurityTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2080 | | { |
| | | 2081 | | // Note: we can sort the table at this point since no other table can reference its rows via RowId or CodedI |
| | | 2082 | | // OrderBy performs a stable sort, so multiple attributes with the same parent will be sorted in the order t |
| | 0 | 2083 | | var ordered = _declSecurityTableNeedsSorting ? _declSecurityTable.OrderBy((x, y) => x.Parent - y.Parent) : _ |
| | | 2084 | | |
| | 0 | 2085 | | foreach (DeclSecurityRow declSecurity in ordered) |
| | 0 | 2086 | | { |
| | 0 | 2087 | | writer.WriteUInt16(declSecurity.Action); |
| | 0 | 2088 | | writer.WriteReference(declSecurity.Parent, metadataSizes.DeclSecurityCodedIndexIsSmall); |
| | 0 | 2089 | | writer.WriteReference(SerializeHandle(declSecurity.PermissionSet), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2090 | | } |
| | 0 | 2091 | | } |
| | | 2092 | | |
| | | 2093 | | private void SerializeClassLayoutTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2094 | | { |
| | 0 | 2095 | | foreach (ClassLayoutRow classLayout in _classLayoutTable) |
| | 0 | 2096 | | { |
| | 0 | 2097 | | writer.WriteUInt16(classLayout.PackingSize); |
| | 0 | 2098 | | writer.WriteUInt32(classLayout.ClassSize); |
| | 0 | 2099 | | writer.WriteReference(classLayout.Parent, metadataSizes.TypeDefReferenceIsSmall); |
| | 0 | 2100 | | } |
| | 0 | 2101 | | } |
| | | 2102 | | |
| | | 2103 | | private void SerializeFieldLayoutTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2104 | | { |
| | 0 | 2105 | | foreach (FieldLayoutRow fieldLayout in _fieldLayoutTable) |
| | 0 | 2106 | | { |
| | 0 | 2107 | | writer.WriteInt32(fieldLayout.Offset); |
| | 0 | 2108 | | writer.WriteReference(fieldLayout.Field, metadataSizes.FieldDefReferenceIsSmall); |
| | 0 | 2109 | | } |
| | 0 | 2110 | | } |
| | | 2111 | | |
| | | 2112 | | private void SerializeStandAloneSigTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2113 | | { |
| | 0 | 2114 | | foreach (StandaloneSigRow row in _standAloneSigTable) |
| | 0 | 2115 | | { |
| | 0 | 2116 | | writer.WriteReference(SerializeHandle(row.Signature), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2117 | | } |
| | 0 | 2118 | | } |
| | | 2119 | | |
| | | 2120 | | private void SerializeEventMapTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2121 | | { |
| | 0 | 2122 | | foreach (EventMapRow eventMap in _eventMapTable) |
| | 0 | 2123 | | { |
| | 0 | 2124 | | writer.WriteReference(eventMap.Parent, metadataSizes.TypeDefReferenceIsSmall); |
| | 0 | 2125 | | writer.WriteReference(eventMap.EventList, metadataSizes.EventDefReferenceIsSmall); |
| | 0 | 2126 | | } |
| | 0 | 2127 | | } |
| | | 2128 | | |
| | | 2129 | | private void SerializeEventTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSizes) |
| | 0 | 2130 | | { |
| | 0 | 2131 | | foreach (EventRow eventRow in _eventTable) |
| | 0 | 2132 | | { |
| | 0 | 2133 | | writer.WriteUInt16(eventRow.EventFlags); |
| | 0 | 2134 | | writer.WriteReference(SerializeHandle(stringMap, eventRow.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 2135 | | writer.WriteReference(eventRow.EventType, metadataSizes.TypeDefOrRefCodedIndexIsSmall); |
| | 0 | 2136 | | } |
| | 0 | 2137 | | } |
| | | 2138 | | |
| | | 2139 | | private void SerializePropertyMapTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2140 | | { |
| | 0 | 2141 | | foreach (PropertyMapRow propertyMap in _propertyMapTable) |
| | 0 | 2142 | | { |
| | 0 | 2143 | | writer.WriteReference(propertyMap.Parent, metadataSizes.TypeDefReferenceIsSmall); |
| | 0 | 2144 | | writer.WriteReference(propertyMap.PropertyList, metadataSizes.PropertyDefReferenceIsSmall); |
| | 0 | 2145 | | } |
| | 0 | 2146 | | } |
| | | 2147 | | |
| | | 2148 | | private void SerializePropertyTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSiz |
| | 0 | 2149 | | { |
| | 0 | 2150 | | foreach (PropertyRow property in _propertyTable) |
| | 0 | 2151 | | { |
| | 0 | 2152 | | writer.WriteUInt16(property.PropFlags); |
| | 0 | 2153 | | writer.WriteReference(SerializeHandle(stringMap, property.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 2154 | | writer.WriteReference(SerializeHandle(property.Type), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2155 | | } |
| | 0 | 2156 | | } |
| | | 2157 | | |
| | | 2158 | | private void SerializeMethodSemanticsTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2159 | | { |
| | | 2160 | | // Note: we can sort the table at this point since no other table can reference its rows via RowId or CodedI |
| | | 2161 | | // OrderBy performs a stable sort, so multiple attributes with the same parent will be sorted in the order t |
| | 0 | 2162 | | var ordered = _methodSemanticsTableNeedsSorting ? _methodSemanticsTable.OrderBy((x, y) => (int)x.Association |
| | | 2163 | | |
| | 0 | 2164 | | foreach (MethodSemanticsRow methodSemantic in ordered) |
| | 0 | 2165 | | { |
| | 0 | 2166 | | writer.WriteUInt16(methodSemantic.Semantic); |
| | 0 | 2167 | | writer.WriteReference(methodSemantic.Method, metadataSizes.MethodDefReferenceIsSmall); |
| | 0 | 2168 | | writer.WriteReference(methodSemantic.Association, metadataSizes.HasSemanticsCodedIndexIsSmall); |
| | 0 | 2169 | | } |
| | 0 | 2170 | | } |
| | | 2171 | | |
| | | 2172 | | private void SerializeMethodImplTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2173 | | { |
| | 0 | 2174 | | foreach (MethodImplRow methodImpl in _methodImplTable) |
| | 0 | 2175 | | { |
| | 0 | 2176 | | writer.WriteReference(methodImpl.Class, metadataSizes.TypeDefReferenceIsSmall); |
| | 0 | 2177 | | writer.WriteReference(methodImpl.MethodBody, metadataSizes.MethodDefOrRefCodedIndexIsSmall); |
| | 0 | 2178 | | writer.WriteReference(methodImpl.MethodDecl, metadataSizes.MethodDefOrRefCodedIndexIsSmall); |
| | 0 | 2179 | | } |
| | 0 | 2180 | | } |
| | | 2181 | | |
| | | 2182 | | private void SerializeModuleRefTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSi |
| | 0 | 2183 | | { |
| | 0 | 2184 | | foreach (ModuleRefRow moduleRef in _moduleRefTable) |
| | 0 | 2185 | | { |
| | 0 | 2186 | | writer.WriteReference(SerializeHandle(stringMap, moduleRef.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 2187 | | } |
| | 0 | 2188 | | } |
| | | 2189 | | |
| | | 2190 | | private void SerializeTypeSpecTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2191 | | { |
| | 0 | 2192 | | foreach (TypeSpecRow typeSpec in _typeSpecTable) |
| | 0 | 2193 | | { |
| | 0 | 2194 | | writer.WriteReference(SerializeHandle(typeSpec.Signature), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2195 | | } |
| | 0 | 2196 | | } |
| | | 2197 | | |
| | | 2198 | | private void SerializeImplMapTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSize |
| | 0 | 2199 | | { |
| | 0 | 2200 | | foreach (ImplMapRow implMap in _implMapTable) |
| | 0 | 2201 | | { |
| | 0 | 2202 | | writer.WriteUInt16(implMap.MappingFlags); |
| | 0 | 2203 | | writer.WriteReference(implMap.MemberForwarded, metadataSizes.MemberForwardedCodedIndexIsSmall); |
| | 0 | 2204 | | writer.WriteReference(SerializeHandle(stringMap, implMap.ImportName), metadataSizes.StringReferenceIsSma |
| | 0 | 2205 | | writer.WriteReference(implMap.ImportScope, metadataSizes.ModuleRefReferenceIsSmall); |
| | 0 | 2206 | | } |
| | 0 | 2207 | | } |
| | | 2208 | | |
| | | 2209 | | private void SerializeFieldRvaTable(BlobBuilder writer, MetadataSizes metadataSizes, int mappedFieldDataStreamRv |
| | 0 | 2210 | | { |
| | 0 | 2211 | | foreach (FieldRvaRow fieldRva in _fieldRvaTable) |
| | 0 | 2212 | | { |
| | 0 | 2213 | | writer.WriteInt32(mappedFieldDataStreamRva + fieldRva.Offset); |
| | 0 | 2214 | | writer.WriteReference(fieldRva.Field, metadataSizes.FieldDefReferenceIsSmall); |
| | 0 | 2215 | | } |
| | 0 | 2216 | | } |
| | | 2217 | | |
| | | 2218 | | private void SerializeAssemblyTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSiz |
| | 0 | 2219 | | { |
| | 0 | 2220 | | if (_assemblyRow.HasValue) |
| | 0 | 2221 | | { |
| | 0 | 2222 | | var version = _assemblyRow.Value.Version; |
| | 0 | 2223 | | writer.WriteUInt32(_assemblyRow.Value.HashAlgorithm); |
| | 0 | 2224 | | writer.WriteUInt16((ushort)version.Major); |
| | 0 | 2225 | | writer.WriteUInt16((ushort)version.Minor); |
| | 0 | 2226 | | writer.WriteUInt16((ushort)version.Build); |
| | 0 | 2227 | | writer.WriteUInt16((ushort)version.Revision); |
| | 0 | 2228 | | writer.WriteUInt32(_assemblyRow.Value.Flags); |
| | 0 | 2229 | | writer.WriteReference(SerializeHandle(_assemblyRow.Value.AssemblyKey), metadataSizes.BlobReferenceIsSmal |
| | 0 | 2230 | | writer.WriteReference(SerializeHandle(stringMap, _assemblyRow.Value.AssemblyName), metadataSizes.StringR |
| | 0 | 2231 | | writer.WriteReference(SerializeHandle(stringMap, _assemblyRow.Value.AssemblyCulture), metadataSizes.Stri |
| | 0 | 2232 | | } |
| | 0 | 2233 | | } |
| | | 2234 | | |
| | | 2235 | | private void SerializeAssemblyRefTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadata |
| | 0 | 2236 | | { |
| | 0 | 2237 | | foreach (AssemblyRefTableRow row in _assemblyRefTable) |
| | 0 | 2238 | | { |
| | 0 | 2239 | | writer.WriteUInt16((ushort)row.Version.Major); |
| | 0 | 2240 | | writer.WriteUInt16((ushort)row.Version.Minor); |
| | 0 | 2241 | | writer.WriteUInt16((ushort)row.Version.Build); |
| | 0 | 2242 | | writer.WriteUInt16((ushort)row.Version.Revision); |
| | 0 | 2243 | | writer.WriteUInt32(row.Flags); |
| | 0 | 2244 | | writer.WriteReference(SerializeHandle(row.PublicKeyToken), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2245 | | writer.WriteReference(SerializeHandle(stringMap, row.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 2246 | | writer.WriteReference(SerializeHandle(stringMap, row.Culture), metadataSizes.StringReferenceIsSmall); |
| | 0 | 2247 | | writer.WriteReference(SerializeHandle(row.HashValue), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2248 | | } |
| | 0 | 2249 | | } |
| | | 2250 | | |
| | | 2251 | | private void SerializeFileTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadataSizes) |
| | 0 | 2252 | | { |
| | 0 | 2253 | | foreach (FileTableRow fileReference in _fileTable) |
| | 0 | 2254 | | { |
| | 0 | 2255 | | writer.WriteUInt32(fileReference.Flags); |
| | 0 | 2256 | | writer.WriteReference(SerializeHandle(stringMap, fileReference.FileName), metadataSizes.StringReferenceI |
| | 0 | 2257 | | writer.WriteReference(SerializeHandle(fileReference.HashValue), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2258 | | } |
| | 0 | 2259 | | } |
| | | 2260 | | |
| | | 2261 | | private void SerializeExportedTypeTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadat |
| | 0 | 2262 | | { |
| | 0 | 2263 | | foreach (ExportedTypeRow exportedType in _exportedTypeTable) |
| | 0 | 2264 | | { |
| | 0 | 2265 | | writer.WriteUInt32(exportedType.Flags); |
| | 0 | 2266 | | writer.WriteInt32(exportedType.TypeDefId); |
| | 0 | 2267 | | writer.WriteReference(SerializeHandle(stringMap, exportedType.TypeName), metadataSizes.StringReferenceIs |
| | 0 | 2268 | | writer.WriteReference(SerializeHandle(stringMap, exportedType.TypeNamespace), metadataSizes.StringRefere |
| | 0 | 2269 | | writer.WriteReference(exportedType.Implementation, metadataSizes.ImplementationCodedIndexIsSmall); |
| | 0 | 2270 | | } |
| | 0 | 2271 | | } |
| | | 2272 | | |
| | | 2273 | | private void SerializeManifestResourceTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes met |
| | 0 | 2274 | | { |
| | 0 | 2275 | | foreach (ManifestResourceRow manifestResource in _manifestResourceTable) |
| | 0 | 2276 | | { |
| | 0 | 2277 | | writer.WriteUInt32(manifestResource.Offset); |
| | 0 | 2278 | | writer.WriteUInt32(manifestResource.Flags); |
| | 0 | 2279 | | writer.WriteReference(SerializeHandle(stringMap, manifestResource.Name), metadataSizes.StringReferenceIs |
| | 0 | 2280 | | writer.WriteReference(manifestResource.Implementation, metadataSizes.ImplementationCodedIndexIsSmall); |
| | 0 | 2281 | | } |
| | 0 | 2282 | | } |
| | | 2283 | | |
| | | 2284 | | private void SerializeNestedClassTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2285 | | { |
| | 0 | 2286 | | foreach (NestedClassRow nestedClass in _nestedClassTable) |
| | 0 | 2287 | | { |
| | 0 | 2288 | | writer.WriteReference(nestedClass.NestedClass, metadataSizes.TypeDefReferenceIsSmall); |
| | 0 | 2289 | | writer.WriteReference(nestedClass.EnclosingClass, metadataSizes.TypeDefReferenceIsSmall); |
| | 0 | 2290 | | } |
| | 0 | 2291 | | } |
| | | 2292 | | |
| | | 2293 | | private void SerializeGenericParamTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metadat |
| | 0 | 2294 | | { |
| | 0 | 2295 | | foreach (GenericParamRow genericParam in _genericParamTable) |
| | 0 | 2296 | | { |
| | 0 | 2297 | | writer.WriteUInt16(genericParam.Number); |
| | 0 | 2298 | | writer.WriteUInt16(genericParam.Flags); |
| | 0 | 2299 | | writer.WriteReference(genericParam.Owner, metadataSizes.TypeOrMethodDefCodedIndexIsSmall); |
| | 0 | 2300 | | writer.WriteReference(SerializeHandle(stringMap, genericParam.Name), metadataSizes.StringReferenceIsSmal |
| | 0 | 2301 | | } |
| | 0 | 2302 | | } |
| | | 2303 | | |
| | | 2304 | | private void SerializeGenericParamConstraintTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2305 | | { |
| | 0 | 2306 | | foreach (GenericParamConstraintRow genericParamConstraint in _genericParamConstraintTable) |
| | 0 | 2307 | | { |
| | 0 | 2308 | | writer.WriteReference(genericParamConstraint.Owner, metadataSizes.GenericParamReferenceIsSmall); |
| | 0 | 2309 | | writer.WriteReference(genericParamConstraint.Constraint, metadataSizes.TypeDefOrRefCodedIndexIsSmall); |
| | 0 | 2310 | | } |
| | 0 | 2311 | | } |
| | | 2312 | | |
| | | 2313 | | private void SerializeMethodSpecTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2314 | | { |
| | 0 | 2315 | | foreach (MethodSpecRow methodSpec in _methodSpecTable) |
| | 0 | 2316 | | { |
| | 0 | 2317 | | writer.WriteReference(methodSpec.Method, metadataSizes.MethodDefOrRefCodedIndexIsSmall); |
| | 0 | 2318 | | writer.WriteReference(SerializeHandle(methodSpec.Instantiation), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2319 | | } |
| | 0 | 2320 | | } |
| | | 2321 | | |
| | | 2322 | | private void SerializeDocumentTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2323 | | { |
| | 0 | 2324 | | foreach (var row in _documentTable) |
| | 0 | 2325 | | { |
| | 0 | 2326 | | writer.WriteReference(SerializeHandle(row.Name), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2327 | | writer.WriteReference(SerializeHandle(row.HashAlgorithm), metadataSizes.GuidReferenceIsSmall); |
| | 0 | 2328 | | writer.WriteReference(SerializeHandle(row.Hash), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2329 | | writer.WriteReference(SerializeHandle(row.Language), metadataSizes.GuidReferenceIsSmall); |
| | 0 | 2330 | | } |
| | 0 | 2331 | | } |
| | | 2332 | | |
| | | 2333 | | private void SerializeMethodDebugInformationTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2334 | | { |
| | 0 | 2335 | | foreach (var row in _methodDebugInformationTable) |
| | 0 | 2336 | | { |
| | 0 | 2337 | | writer.WriteReference(row.Document, metadataSizes.DocumentReferenceIsSmall); |
| | 0 | 2338 | | writer.WriteReference(SerializeHandle(row.SequencePoints), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2339 | | } |
| | 0 | 2340 | | } |
| | | 2341 | | |
| | | 2342 | | private void SerializeLocalScopeTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2343 | | { |
| | 0 | 2344 | | foreach (var row in _localScopeTable) |
| | 0 | 2345 | | { |
| | 0 | 2346 | | writer.WriteReference(row.Method, metadataSizes.MethodDefReferenceIsSmall); |
| | 0 | 2347 | | writer.WriteReference(row.ImportScope, metadataSizes.ImportScopeReferenceIsSmall); |
| | 0 | 2348 | | writer.WriteReference(row.VariableList, metadataSizes.LocalVariableReferenceIsSmall); |
| | 0 | 2349 | | writer.WriteReference(row.ConstantList, metadataSizes.LocalConstantReferenceIsSmall); |
| | 0 | 2350 | | writer.WriteInt32(row.StartOffset); |
| | 0 | 2351 | | writer.WriteInt32(row.Length); |
| | 0 | 2352 | | } |
| | 0 | 2353 | | } |
| | | 2354 | | |
| | | 2355 | | private void SerializeLocalVariableTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metada |
| | 0 | 2356 | | { |
| | 0 | 2357 | | foreach (var row in _localVariableTable) |
| | 0 | 2358 | | { |
| | 0 | 2359 | | writer.WriteUInt16(row.Attributes); |
| | 0 | 2360 | | writer.WriteUInt16(row.Index); |
| | 0 | 2361 | | writer.WriteReference(SerializeHandle(stringMap, row.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 2362 | | } |
| | 0 | 2363 | | } |
| | | 2364 | | |
| | | 2365 | | private void SerializeLocalConstantTable(BlobBuilder writer, ImmutableArray<int> stringMap, MetadataSizes metada |
| | 0 | 2366 | | { |
| | 0 | 2367 | | foreach (var row in _localConstantTable) |
| | 0 | 2368 | | { |
| | 0 | 2369 | | writer.WriteReference(SerializeHandle(stringMap, row.Name), metadataSizes.StringReferenceIsSmall); |
| | 0 | 2370 | | writer.WriteReference(SerializeHandle(row.Signature), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2371 | | } |
| | 0 | 2372 | | } |
| | | 2373 | | |
| | | 2374 | | private void SerializeImportScopeTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2375 | | { |
| | 0 | 2376 | | foreach (var row in _importScopeTable) |
| | 0 | 2377 | | { |
| | 0 | 2378 | | writer.WriteReference(row.Parent, metadataSizes.ImportScopeReferenceIsSmall); |
| | 0 | 2379 | | writer.WriteReference(SerializeHandle(row.Imports), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2380 | | } |
| | 0 | 2381 | | } |
| | | 2382 | | |
| | | 2383 | | private void SerializeStateMachineMethodTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2384 | | { |
| | 0 | 2385 | | foreach (var row in _stateMachineMethodTable) |
| | 0 | 2386 | | { |
| | 0 | 2387 | | writer.WriteReference(row.MoveNextMethod, metadataSizes.MethodDefReferenceIsSmall); |
| | 0 | 2388 | | writer.WriteReference(row.KickoffMethod, metadataSizes.MethodDefReferenceIsSmall); |
| | 0 | 2389 | | } |
| | 0 | 2390 | | } |
| | | 2391 | | |
| | | 2392 | | private void SerializeCustomDebugInformationTable(BlobBuilder writer, MetadataSizes metadataSizes) |
| | 0 | 2393 | | { |
| | | 2394 | | // Note: we can sort the table at this point since no other table can reference its rows via RowId or CodedI |
| | | 2395 | | // OrderBy performs a stable sort, so multiple attributes with the same parent and kind will be sorted in th |
| | 0 | 2396 | | foreach (CustomDebugInformationRow row in _customDebugInformationTable.OrderBy((x, y) => |
| | 0 | 2397 | | { |
| | 0 | 2398 | | int result = x.Parent - y.Parent; |
| | 0 | 2399 | | return (result != 0) ? result : x.Kind.Index - y.Kind.Index; |
| | 0 | 2400 | | })) |
| | 0 | 2401 | | { |
| | 0 | 2402 | | writer.WriteReference(row.Parent, metadataSizes.HasCustomDebugInformationCodedIndexIsSmall); |
| | 0 | 2403 | | writer.WriteReference(SerializeHandle(row.Kind), metadataSizes.GuidReferenceIsSmall); |
| | 0 | 2404 | | writer.WriteReference(SerializeHandle(row.Value), metadataSizes.BlobReferenceIsSmall); |
| | 0 | 2405 | | } |
| | 0 | 2406 | | } |
| | | 2407 | | |
| | | 2408 | | #endregion |
| | | 2409 | | } |
| | | 2410 | | } |
| | | 2411 | | |