/// <summary>
        /// Initializes a new instance of the <see cref="CilRuntimeType"/> class.
        /// </summary>
        /// <param name="moduleTypeSystem">The module type system.</param>
        /// <param name="token">The token.</param>
        /// <param name="typeDefRow">The type def row.</param>
        /// <param name="maxField">The max field.</param>
        /// <param name="maxMethod">The max method.</param>
        /// <param name="packing">The packing.</param>
        /// <param name="size">The size.</param>
        public CilRuntimeType(IModuleTypeSystem moduleTypeSystem, TokenTypes token, TypeDefRow typeDefRow, TokenTypes maxField, TokenTypes maxMethod, int packing, int size)
            : base(moduleTypeSystem, (int)token)
        {
            this.baseTypeToken = typeDefRow.Extends;
            this.nameIdx = typeDefRow.TypeNameIdx;
            this.namespaceIdx = typeDefRow.TypeNamespaceIdx;

            base.Attributes = typeDefRow.Flags;
            base.Pack = packing;
            base.Size = size;

            // Load all fields of the type
            int members = maxField - typeDefRow.FieldList;
            if (0 < members)
            {
                int i = (int)(typeDefRow.FieldList & TokenTypes.RowIndexMask) - 1;
                base.Fields = new ReadOnlyRuntimeFieldListView((IModuleTypeSystemInternalList)moduleTypeSystem, i, members);
            }
            else
            {
                base.Fields = ReadOnlyRuntimeFieldListView.Empty;
            }

            // Load all methods of the type
            members = maxMethod - typeDefRow.MethodList;
            if (0 < members)
            {
                int i = (int)(typeDefRow.MethodList & TokenTypes.RowIndexMask) - 1;
                base.Methods = new ReadOnlyRuntimeMethodListView((IModuleTypeSystemInternalList)moduleTypeSystem, i, members);
            }
            else
            {
                base.Methods = ReadOnlyRuntimeMethodListView.Empty;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CilRuntimeType"/> class.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="module">The module.</param>
        /// <param name="typeDefRow">The type def row.</param>
        /// <param name="maxField">The max field.</param>
        /// <param name="maxMethod">The max method.</param>
        /// <param name="packing">The packing.</param>
        /// <param name="size">The size.</param>
        public CilRuntimeType(TokenTypes token, IMetadataModule module, ref TypeDefRow typeDefRow, TokenTypes maxField, TokenTypes maxMethod, int packing, int size)
            : base((int)token, module)
        {
            this.baseTypeToken = typeDefRow.Extends;
            this.module = module;
            this.nameIdx = typeDefRow.TypeNameIdx;
            this.namespaceIdx = typeDefRow.TypeNamespaceIdx;

            base.Attributes = typeDefRow.Flags;
            base.Pack = packing;
            base.Size = size;

            // Load all fields of the type
            int members = maxField - typeDefRow.FieldList;
            if (0 < members)
            {
                int i = (int)(typeDefRow.FieldList & TokenTypes.RowIndexMask) - 1 + RuntimeBase.Instance.TypeLoader.GetModuleOffset(module).FieldOffset;
                base.Fields = new ReadOnlyRuntimeFieldListView(i, members);
            }
            else
            {
                base.Fields = ReadOnlyRuntimeFieldListView.Empty;
            }

            // Load all methods of the type
            members = maxMethod - typeDefRow.MethodList;
            if (0 < members)
            {
                int i = (int)(typeDefRow.MethodList & TokenTypes.RowIndexMask) - 1 + RuntimeBase.Instance.TypeLoader.GetModuleOffset(module).MethodOffset;
                base.Methods = new ReadOnlyRuntimeMethodListView(i, members);
            }
            else
            {
                base.Methods = ReadOnlyRuntimeMethodListView.Empty;
            }
        }
 void IMetadataProvider.Read(TokenTypes token, out TypeDefRow result)
 {
     TableHeap theap = (TableHeap)_streams[(int)HeapType.Tables];
     theap.Read(token, out result);
 }
Exemple #4
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="result">The result.</param>
        public void Read(TokenTypes token, out TypeDefRow result)
        {
            if ((token & TokenTypes.TableMask) != TokenTypes.TypeDef)
                throw new ArgumentException ("Invalid token type for TypeDefRow.", "token");

            using (BinaryReader reader = CreateReaderForToken (token))
            {
                result = new TypeDefRow ((TypeAttributes)reader.ReadUInt32 (), ReadIndexValue (reader, IndexType.StringHeap), ReadIndexValue (reader, IndexType.StringHeap), ReadIndexValue (reader, IndexType.TypeDefOrRef), ReadIndexValue (reader, TokenTypes.Field), ReadIndexValue (reader, TokenTypes.MethodDef));
            }
        }
        /// <summary>
        /// Loads all types from the given metadata module.
        /// </summary>
        private void LoadTypes()
        {
            TokenTypes maxTypeDef, maxField, maxMethod, maxLayout, tokenLayout = TokenTypes.ClassLayout + 1;
            TypeDefRow typeDefRow, nextTypeDefRow = new TypeDefRow();
            ClassLayoutRow layoutRow = new ClassLayoutRow();
            int size = 0x0, packing = 0;
            int typeOffset = 0;
            int methodOffset = 0;
            int fieldOffset = 0;
            RuntimeType rt;

            maxTypeDef = metadata.GetMaxTokenValue(TokenTypes.TypeDef);
            maxLayout = metadata.GetMaxTokenValue(TokenTypes.ClassLayout);
            maxMethod = metadata.GetMaxTokenValue(TokenTypes.MethodDef);
            maxField = metadata.GetMaxTokenValue(TokenTypes.Field);

            if (TokenTypes.ClassLayout < maxLayout)
                layoutRow = metadata.ReadClassLayoutRow(tokenLayout);

            TokenTypes token = TokenTypes.TypeDef + 1;
            typeDefRow = metadata.ReadTypeDefRow(token);

            for (; token <= maxTypeDef; token++)
            {
                TokenTypes maxNextMethod, maxNextField;
                string name = metadata.ReadString(typeDefRow.TypeNameIdx);

                //Debug.Write(((uint)token).ToString("X") + ": ");
                //Debug.Write(typeDefRow.TypeNameIdx.ToString("X") + ": ");
                //Debug.Write(metadata.ReadString(typeDefRow.TypeNameIdx));

                if (token < maxTypeDef)
                {
                    nextTypeDefRow = metadata.ReadTypeDefRow(token + 1);
                    maxNextField = nextTypeDefRow.FieldList;
                    maxNextMethod = nextTypeDefRow.MethodList;

                    if (maxNextMethod > maxMethod)
                        maxNextMethod = maxMethod + 1;
                    if (maxNextField > maxField)
                        maxNextField = maxField + 1;
                }
                else
                {
                    maxNextMethod = maxMethod + 1;
                    maxNextField = maxField + 1;
                }

                // Is this our layout info?
                if (layoutRow.ParentTypeDefIdx == token)
                {
                    size = layoutRow.ClassSize;
                    packing = layoutRow.PackingSize;

                    //Debug.Write(" [Size: " + size.ToString() + "]");

                    tokenLayout++;
                    if (tokenLayout <= maxLayout)
                        layoutRow = metadata.ReadClassLayoutRow(tokenLayout);
                }
                //Debug.WriteLine(string.Empty);

                // Create and populate the runtime type
                rt = new CilRuntimeType(this, token, typeDefRow, maxNextField, maxNextMethod, packing, size);
                LoadMethods(rt, typeDefRow.MethodList, maxNextMethod, ref methodOffset);
                LoadFields(rt, typeDefRow.FieldList, maxNextField, ref fieldOffset);
                types[typeOffset++] = rt;

                packing = size = 0;
                typeDefRow = nextTypeDefRow;
            }
        }
 public TypeDefRowExt(IMetadataProvider metadata, TypeDefRow row)
     : base(metadata)
 {
     this.row = row;
 }