/// <summary>
        /// Loads all fields defined in the module.
        /// </summary>
        /// <param name="declaringType">The type, which declared the method.</param>
        /// <param name="first">The first field token to load.</param>
        /// <param name="last">The last field token to load (non-inclusive.)</param>
        /// <param name="offset">The offset in the fields array.</param>
        private void LoadFields(RuntimeType declaringType, TokenTypes first, TokenTypes last, ref int offset)
        {
            TokenTypes maxRVA = metadata.GetMaxTokenValue(TokenTypes.FieldRVA);
            TokenTypes maxLayout = metadata.GetMaxTokenValue(TokenTypes.FieldLayout);
            TokenTypes tokenRva = TokenTypes.FieldRVA + 1;
            TokenTypes tokenLayout = TokenTypes.FieldLayout + 1;

            FieldRVARow fieldRVA = new FieldRVARow();
            FieldLayoutRow fieldLayout = new FieldLayoutRow();

            if (TokenTypes.FieldRVA < maxRVA)
                fieldRVA = metadata.ReadFieldRVARow(tokenRva);

            if (TokenTypes.FieldLayout < maxLayout)
                fieldLayout = metadata.ReadFieldLayoutRow(tokenLayout);

            for (TokenTypes token = first; token < last; token++)
            {
                // Read the stackFrameIndex
                FieldRow field = metadata.ReadFieldRow(token);
                uint rva = 0;
                uint layout = 0;

                // Static fields have an optional RVA, non-static may have a layout assigned
                if ((field.Flags & FieldAttributes.HasFieldRVA) == FieldAttributes.HasFieldRVA)
                {
                    // Move to the RVA of this field
                    while (fieldRVA.FieldTableIdx < token && tokenRva <= maxRVA)
                        fieldRVA = metadata.ReadFieldRVARow(tokenRva++);

                    // Does this field have an RVA?
                    if (token == fieldRVA.FieldTableIdx && tokenRva <= maxRVA)
                    {
                        rva = fieldRVA.Rva;
                        tokenRva++;
                        if (tokenRva < maxRVA)
                        {
                            fieldRVA = metadata.ReadFieldRVARow(tokenRva);
                        }
                    }
                }

                if ((field.Flags & FieldAttributes.HasDefault) == FieldAttributes.HasDefault)
                {
                    // FIXME: Has a default value.
                    //Debug.Assert(false);
                }

                // Layout only exists for non-static fields
                if ((field.Flags & FieldAttributes.Static) != FieldAttributes.Static)
                {
                    // Move to the layout of this field
                    while (fieldLayout.Field < token && tokenLayout <= maxLayout)
                        fieldLayout = metadata.ReadFieldLayoutRow(tokenLayout++);

                    // Does this field have layout?
                    if (token == fieldLayout.Field && tokenLayout <= maxLayout)
                    {
                        layout = fieldLayout.Offset;
                        tokenLayout++;
                        if (tokenLayout < maxLayout)
                        {
                            fieldLayout = metadata.ReadFieldLayoutRow(tokenLayout);
                        }
                    }
                }

                // Load the field metadata
                fields[offset++] = new CilRuntimeField(this, field, layout, rva, declaringType);
            }

            /* FIXME:
             * Load FieldMarshal tables
             * as needed afterwards. All Generics have been loaded, fields can receive
             * their signature in the load method above.
             */
        }
Exemplo n.º 2
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        public override bool Equals(RuntimeField other)
        {
            CilRuntimeField crf = other as CilRuntimeField;

            return(crf != null && this.nameIdx == crf.nameIdx && this.signature == crf.signature && base.Equals(other) == true);
        }