internal static int GetCodedIndexSize (CodedIndex ci, TableRowCounter rowCounter, int [] codedIndexCache) { int bits = 0, max = 0, index = (int) ci; if (codedIndexCache [index] != 0) return codedIndexCache [index]; int res = 0; int [] rids; switch (ci) { case CodedIndex.TypeDefOrRef : bits = 2; rids = new int [3]; rids [0] = TypeDefTable.RId; rids [1] = TypeRefTable.RId; rids [2] = TypeSpecTable.RId; break; case CodedIndex.HasConstant : bits = 2; rids = new int [3]; rids [0] = FieldTable.RId; rids [1] = ParamTable.RId; rids [2] = PropertyTable.RId; break; case CodedIndex.HasCustomAttribute : bits = 5; rids = new int [20]; rids [0] = MethodTable.RId; rids [1] = FieldTable.RId; rids [2] = TypeRefTable.RId; rids [3] = TypeDefTable.RId; rids [4] = ParamTable.RId; rids [5] = InterfaceImplTable.RId; rids [6] = MemberRefTable.RId; rids [7] = ModuleTable.RId; rids [8] = DeclSecurityTable.RId; rids [9] = PropertyTable.RId; rids [10] = EventTable.RId; rids [11] = StandAloneSigTable.RId; rids [12] = ModuleRefTable.RId; rids [13] = TypeSpecTable.RId; rids [14] = AssemblyTable.RId; rids [15] = AssemblyRefTable.RId; rids [16] = FileTable.RId; rids [17] = ExportedTypeTable.RId; rids [18] = ManifestResourceTable.RId; rids [19] = GenericParamTable.RId; break; case CodedIndex.HasFieldMarshal : bits = 1; rids = new int [2]; rids [0] = FieldTable.RId; rids [1] = ParamTable.RId; break; case CodedIndex.HasDeclSecurity : bits = 2; rids = new int [3]; rids [0] = TypeDefTable.RId; rids [1] = MethodTable.RId; rids [2] = AssemblyTable.RId; break; case CodedIndex.MemberRefParent : bits = 3; rids = new int [5]; rids [0] = TypeDefTable.RId; rids [1] = TypeRefTable.RId; rids [2] = ModuleRefTable.RId; rids [3] = MethodTable.RId; rids [4] = TypeSpecTable.RId; break; case CodedIndex.HasSemantics : bits = 1; rids = new int [2]; rids [0] = EventTable.RId; rids [1] = PropertyTable.RId; break; case CodedIndex.MethodDefOrRef : bits = 1; rids = new int [2]; rids [0] = MethodTable.RId; rids [1] = MemberRefTable.RId; break; case CodedIndex.MemberForwarded : bits = 1; rids = new int [2]; rids [0] = FieldTable.RId; rids [1] = MethodTable.RId; break; case CodedIndex.Implementation : bits = 2; rids = new int [3]; rids [0] = FileTable.RId; rids [1] = AssemblyRefTable.RId; rids [2] = ExportedTypeTable.RId; break; case CodedIndex.CustomAttributeType : bits = 3; rids = new int [2]; rids [0] = MethodTable.RId; rids [1] = MemberRefTable.RId; break; case CodedIndex.ResolutionScope : bits = 2; rids = new int [4]; rids [0] = ModuleTable.RId; rids [1] = ModuleRefTable.RId; rids [2] = AssemblyRefTable.RId; rids [3] = TypeRefTable.RId; break; case CodedIndex.TypeOrMethodDef : bits = 1; rids = new int [2]; rids [0] = TypeDefTable.RId; rids [1] = MethodTable.RId; break; default : throw new MetadataFormatException ("Non valid CodedIndex"); } for (int i = 0; i < rids.Length; i++) { int rows = rowCounter (rids [i]); if (rows > max) max = rows; } res = max < (1 << (16 - bits)) ? 2 : 4; codedIndexCache [index] = res; return res; }
internal static int GetCodedIndexSize(CodedIndex ci, TableRowCounter rowCounter, int [] codedIndexCache) { int bits = 0, max = 0, index = (int)ci; if (codedIndexCache [index] != 0) { return(codedIndexCache [index]); } int res = 0; int [] rids; switch (ci) { case CodedIndex.TypeDefOrRef: bits = 2; rids = new int [3]; rids [0] = TypeDefTable.RId; rids [1] = TypeRefTable.RId; rids [2] = TypeSpecTable.RId; break; case CodedIndex.HasConstant: bits = 2; rids = new int [3]; rids [0] = FieldTable.RId; rids [1] = ParamTable.RId; rids [2] = PropertyTable.RId; break; case CodedIndex.HasCustomAttribute: bits = 5; rids = new int [20]; rids [0] = MethodTable.RId; rids [1] = FieldTable.RId; rids [2] = TypeRefTable.RId; rids [3] = TypeDefTable.RId; rids [4] = ParamTable.RId; rids [5] = InterfaceImplTable.RId; rids [6] = MemberRefTable.RId; rids [7] = ModuleTable.RId; rids [8] = DeclSecurityTable.RId; rids [9] = PropertyTable.RId; rids [10] = EventTable.RId; rids [11] = StandAloneSigTable.RId; rids [12] = ModuleRefTable.RId; rids [13] = TypeSpecTable.RId; rids [14] = AssemblyTable.RId; rids [15] = AssemblyRefTable.RId; rids [16] = FileTable.RId; rids [17] = ExportedTypeTable.RId; rids [18] = ManifestResourceTable.RId; rids [19] = GenericParamTable.RId; break; case CodedIndex.HasFieldMarshal: bits = 1; rids = new int [2]; rids [0] = FieldTable.RId; rids [1] = ParamTable.RId; break; case CodedIndex.HasDeclSecurity: bits = 2; rids = new int [3]; rids [0] = TypeDefTable.RId; rids [1] = MethodTable.RId; rids [2] = AssemblyTable.RId; break; case CodedIndex.MemberRefParent: bits = 3; rids = new int [5]; rids [0] = TypeDefTable.RId; rids [1] = TypeRefTable.RId; rids [2] = ModuleRefTable.RId; rids [3] = MethodTable.RId; rids [4] = TypeSpecTable.RId; break; case CodedIndex.HasSemantics: bits = 1; rids = new int [2]; rids [0] = EventTable.RId; rids [1] = PropertyTable.RId; break; case CodedIndex.MethodDefOrRef: bits = 1; rids = new int [2]; rids [0] = MethodTable.RId; rids [1] = MemberRefTable.RId; break; case CodedIndex.MemberForwarded: bits = 1; rids = new int [2]; rids [0] = FieldTable.RId; rids [1] = MethodTable.RId; break; case CodedIndex.Implementation: bits = 2; rids = new int [3]; rids [0] = FileTable.RId; rids [1] = AssemblyRefTable.RId; rids [2] = ExportedTypeTable.RId; break; case CodedIndex.CustomAttributeType: bits = 3; rids = new int [2]; rids [0] = MethodTable.RId; rids [1] = MemberRefTable.RId; break; case CodedIndex.ResolutionScope: bits = 2; rids = new int [4]; rids [0] = ModuleTable.RId; rids [1] = ModuleRefTable.RId; rids [2] = AssemblyRefTable.RId; rids [3] = TypeRefTable.RId; break; case CodedIndex.TypeOrMethodDef: bits = 1; rids = new int [2]; rids [0] = TypeDefTable.RId; rids [1] = MethodTable.RId; break; default: throw new MetadataFormatException("Non valid CodedIndex"); } for (int i = 0; i < rids.Length; i++) { int rows = rowCounter(rids [i]); if (rows > max) { max = rows; } } res = max < (1 << (16 - bits)) ? 2 : 4; codedIndexCache [index] = res; return(res); }