/// <summary>Create instance of MetaTable column class</summary> /// <param name="tableType">Owner table type</param> /// <param name="columnType">Column type</param> /// <param name="columnName">Column name</param> /// <param name="columnIndex">Column index in table</param> public MetaColumn(Cor.MetaTableType tableType, MetaColumnType columnType, String columnName, UInt16 columnIndex) { this._tableType = tableType; this._columnType = columnType; this._columnName = columnName; this._columnIndex = columnIndex; }
/// <summary>Создать таблицу мета-данных</summary> /// <param name="tableType">Тип создаваемой таблицы</param> /// <param name="padding">Отступ от начала потока с мета данными</param> private void AddTable(Cor.MetaTableType tableType, ref UInt32 padding) { MetaTable table = new MetaTable(this, tableType, padding); padding += table.TableSize; this._tables.Add(tableType, table); }
//[Conditional("DEBUG")] public static String CteateMetaTableProperty(Cor.MetaTableType tableType) { return(String.Format(@"public Tables.BaseMetaTable<Tables.{0}TableRow> {0} {{ get {{ return new Tables.BaseMetaTable<Tables.{0}TableRow>(this, MetaTableType.{0}); }} }} ", tableType)); }
/// <summary>Получить кол-во рядов в определённой таблице</summary> /// <param name="tableType">Таблица для которой получить кол-во рядов</param> /// <returns>Кол-во рядов в определённой таблице</returns> public UInt32 GetRowsCount(Cor.MetaTableType tableType) { if (this._rowsCount == null) { this._rowsCount = this.GetRowsCount(); } return(this._rowsCount[(Int32)tableType]); }
/// <summary>Создание экземпляра базового класса детализированного описания таблицы в метаданных</summary> /// <param name="stream">Поток</param> /// <param name="type">Тип таблицы</param> internal BaseMetaTable(StreamTables stream, Cor.MetaTableType type) { if (stream == null) { throw new ArgumentNullException("stream"); } this._tableType = type; this._table = stream[this._tableType]; }
/// <summary>Создание экземпляра класса мета-таблицы</summary> /// <param name="root">Корневой поток</param> /// <param name="tableType">Тип таблицы</param> /// <param name="padding">Отступ от начала потома метаданных</param> /// <exception cref="T:ArgumentNullException">root is null</exception> public MetaTable(StreamTables root, Cor.MetaTableType tableType, UInt32 padding) { if (root == null) { throw new ArgumentNullException("root"); } this._root = root; this._tableType = tableType; this._padding = padding; this._columns = MetaTable.GetTableDescription(this.TableType); }
/// <summary>Таблица с информацией о типе</summary> /// <param name="tableType">Тип таблицы</param> /// <returns>Данные в таблице</returns> public MetaTable this[Cor.MetaTableType tableType] { get { if (this._tables == null) { DataBind(); } MetaTable result; if (this._tables.TryGetValue(tableType, out result)) { return(result); } else { return(null); } } }
/// <summary>Получить описатель таблицы</summary> /// <param name="table">Таблица для получения колонок</param> /// <exception cref="T:NotSupportedException">Unknown table</exception> /// <exception cref="T:InvalidOperationException">Column names not equal column types</exception> /// <returns>Массив колонок в таблице</returns> private static MetaColumn[] GetTableDescription(Cor.MetaTableType table) { MetaColumnType[] columnType; String[] columnName; switch (table) { case Cor.MetaTableType.Module: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.String, MetaColumnType.Guid, MetaColumnType.Guid, MetaColumnType.Guid, }; columnName = new String[] { "Generation", "Name", "Mvid", "EncId", "EncBaseId", }; break; case Cor.MetaTableType.TypeRef: columnType = new MetaColumnType[] { MetaColumnType.ResolutionScope, MetaColumnType.String, MetaColumnType.String, }; columnName = new String[] { "ResolutionScope", "TypeName", "TypeNamespace" }; break; case Cor.MetaTableType.TypeDef: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.String, MetaColumnType.String, MetaColumnType.TypeDefOrRef, MetaColumnType.Field, MetaColumnType.MethodDef, }; columnName = new String[] { "Flags", "TypeName", "TypeNamespace", "Extends", "FieldList", "MethodList", }; break; case Cor.MetaTableType.FieldPtr: columnType = new MetaColumnType[] { MetaColumnType.Field, }; columnName = new String[] { "Field" }; break; case Cor.MetaTableType.Field: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.String, MetaColumnType.Blob, }; columnName = new String[] { "Flags", "Name", "Signature", }; break; case Cor.MetaTableType.MethodPtr: columnType = new MetaColumnType[] { MetaColumnType.MethodDef, }; columnName = new String[] { "Method", }; break; case Cor.MetaTableType.MethodDef: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.String, MetaColumnType.Blob, MetaColumnType.Param, }; columnName = new String[] { "RVA", "ImplFlags", "Flags", "Name", "Signature", "ParamList", }; break; case Cor.MetaTableType.ParamPtr: columnType = new MetaColumnType[] { MetaColumnType.Param, }; columnName = new String[] { "Param", }; break; case Cor.MetaTableType.Param: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.String, }; columnName = new String[] { "Flags", "Sequence", "Name", }; break; case Cor.MetaTableType.InterfaceImpl: columnType = new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.TypeDefOrRef, }; columnName = new String[] { "Class", "Interface", }; break; case Cor.MetaTableType.MemberRef: columnType = new MetaColumnType[] { MetaColumnType.MemberRefParent, MetaColumnType.String, MetaColumnType.Blob, }; columnName = new String[] { "Class", "Name", "Signature", }; break; case Cor.MetaTableType.Constant: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.HasConstant, MetaColumnType.Blob, }; columnName = new String[] { "Type", "Parent", "Value", }; break; case Cor.MetaTableType.CustomAttribute: columnType = new MetaColumnType[] { MetaColumnType.HasCustomAttribute, MetaColumnType.CustomAttributeType, MetaColumnType.Blob, }; columnName = new String[] { "Parent", "Type", "Value", }; break; case Cor.MetaTableType.FieldMarshal: columnType = new MetaColumnType[] { MetaColumnType.HasFieldMarshal, MetaColumnType.Blob, }; columnName = new String[] { "Parent", "Native", }; break; case Cor.MetaTableType.DeclSecurity: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.HasDeclSecurity, MetaColumnType.Blob, }; columnName = new String[] { "Action", "Parent", "PermissionSet", }; break; case Cor.MetaTableType.ClassLayout: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.UInt32, MetaColumnType.TypeDef, }; columnName = new String[] { "PackingSize", "ClassSize", "Parent", }; break; case Cor.MetaTableType.FieldLayout: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.Field, }; columnName = new String[] { "Offset", "Field", }; break; case Cor.MetaTableType.StandAloneSig: columnType = new MetaColumnType[] { MetaColumnType.Blob, }; columnName = new String[] { "Signature", }; break; case Cor.MetaTableType.EventMap: columnType = new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.Event, }; columnName = new String[] { "Parent", "EventList", }; break; case Cor.MetaTableType.EventPtr: columnType = new MetaColumnType[] { MetaColumnType.Event, }; columnName = new String[] { "Event", }; break; case Cor.MetaTableType.Event: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.String, MetaColumnType.TypeDefOrRef, }; columnName = new String[] { "EventFlags", "Name", "EventType", }; break; case Cor.MetaTableType.PropertyMap: columnType = new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.Property, }; columnName = new String[] { "Parent", "PropertyList", }; break; case Cor.MetaTableType.PropertyPtr: columnType = new MetaColumnType[] { MetaColumnType.Property, }; columnName = new String[] { "Property", }; break; case Cor.MetaTableType.Property: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.String, MetaColumnType.Blob, }; columnName = new String[] { "Flags", "Name", "Type", }; break; case Cor.MetaTableType.MethodSemantics: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.MethodDef, MetaColumnType.HasSemantic, }; columnName = new String[] { "Semantic", "Method", "Association", }; break; case Cor.MetaTableType.MethodImpl: columnType = new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.MethodDefOrRef, MetaColumnType.MethodDefOrRef, }; columnName = new String[] { "Class", "MethodBody", "MethodDeclaration", }; break; case Cor.MetaTableType.ModuleRef: columnType = new MetaColumnType[] { MetaColumnType.String, }; columnName = new String[] { "Name", }; break; case Cor.MetaTableType.TypeSpec: columnType = new MetaColumnType[] { MetaColumnType.Blob, }; columnName = new String[] { "Signature", }; break; case Cor.MetaTableType.ImplMap: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.MemberForwarded, MetaColumnType.String, MetaColumnType.ModuleRef, }; columnName = new String[] { "MappingFlags", "MemberForwarded", "ImportName", "ImportScope", }; break; case Cor.MetaTableType.FieldRVA: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.Field, }; columnName = new String[] { "RVA", "Field", }; break; case Cor.MetaTableType.ENCLog: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt32, }; columnName = new String[] { "Token", "FuncCode", }; break; case Cor.MetaTableType.ENCMap: columnType = new MetaColumnType[] { MetaColumnType.UInt32, }; columnName = new String[] { "Token", }; break; case Cor.MetaTableType.Assembly: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt32, MetaColumnType.Blob, MetaColumnType.String, MetaColumnType.String, }; columnName = new String[] { "HashAlgId", "MajorVersion", "MinorVersion", "BuildNumber", "RevisionNumber", "Flags", "PublicKey", "Name", "Locale", }; break; case Cor.MetaTableType.AssemblyProcessor: columnType = new MetaColumnType[] { MetaColumnType.UInt32, }; columnName = new String[] { "Processor", }; break; case Cor.MetaTableType.AssemblyOS: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt32, MetaColumnType.UInt32, }; columnName = new String[] { "OSPlatformId", "OSMajorVersion", "OSMinorVersion", }; break; case Cor.MetaTableType.AssemblyRef: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.UInt32, MetaColumnType.Blob, MetaColumnType.String, MetaColumnType.String, MetaColumnType.Blob, }; columnName = new String[] { "MajorVersion", "MinorVersion", "BuildNumber", "RevisionNumber", "Flags", "PublicKeyOrToken", "Name", "Locale", "HashValue", }; break; case Cor.MetaTableType.AssemblyRefProcessor: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.AssemblyRef, }; columnName = new String[] { "Processor", "AssemblyRef", }; break; case Cor.MetaTableType.AssemblyRefOS: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt32, MetaColumnType.UInt32, MetaColumnType.AssemblyRef, }; columnName = new String[] { "OSPlatformId", "OSMajorVersion", "OSMinorVersion", "AssemblyRef", }; break; case Cor.MetaTableType.File: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.String, MetaColumnType.Blob, }; columnName = new String[] { "Flags", "Name", "HashValue", }; break; case Cor.MetaTableType.ExportedType: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt32, MetaColumnType.String, MetaColumnType.String, MetaColumnType.Implementation, }; columnName = new String[] { "Flags", "TypeDefId", "TypeName", "TypeNamespace", "Implementation", }; break; case Cor.MetaTableType.ManifestResource: columnType = new MetaColumnType[] { MetaColumnType.UInt32, MetaColumnType.UInt32, MetaColumnType.String, MetaColumnType.Implementation, }; columnName = new String[] { "Offset", "Flags", "Name", "Implementation", }; break; case Cor.MetaTableType.NestedClass: columnType = new MetaColumnType[] { MetaColumnType.TypeDef, MetaColumnType.TypeDef, }; columnName = new String[] { "NestedClass", "EnclosingClass", }; break; case Cor.MetaTableType.GenericParam: columnType = new MetaColumnType[] { MetaColumnType.UInt16, MetaColumnType.UInt16, MetaColumnType.TypeOrMethodDef, MetaColumnType.String, }; columnName = new String[] { "Number", "Flags", "Owner", "Name", }; break; case Cor.MetaTableType.MethodSpec: columnType = new MetaColumnType[] { MetaColumnType.MethodDefOrRef, MetaColumnType.Blob, }; columnName = new String[] { "Method", "Instantiation", }; break; case Cor.MetaTableType.GenericParamConstraint: columnType = new MetaColumnType[] { MetaColumnType.GenericParam, MetaColumnType.TypeDefOrRef, }; columnName = new String[] { "Owner", "Constraint", }; break; default: throw new NotSupportedException(); } if (columnType.Length != columnName.Length) { throw new InvalidOperationException("Length of column type and names must be equal"); } MetaColumn[] result = new MetaColumn[columnType.Length]; for (UInt16 loop = 0; loop < result.Length; loop++) { result[loop] = new MetaColumn(table, columnType[loop], columnName[loop], loop); } return(result); }
/// <summary>Create instance of base cell pointer class</summary> /// <param name="cell">Source cell</param> /// <param name="rowIndex">Target row index</param> /// <param name="tableType">Target table type</param> internal CellPointerBase(MetaCell cell, UInt32 rowIndex, Cor.MetaTableType tableType) { this._cell = cell; this._rowIndex = rowIndex == 0 ? (UInt32?)null : checked (rowIndex - 1); //TODO: Почему -1? (Код вылетает в Overflow в таблице TypeDef в TypeName=<Module>) this._tableType = tableType; }