Example #1
0
        void ReadConstants()
        {
            if (!m_tHeap.HasTable(ConstantTable.RId))
            {
                return;
            }

            ConstantTable csTable = m_tableReader.GetConstantTable();

            for (int i = 0; i < csTable.Rows.Count; i++)
            {
                ConstantRow csRow = csTable [i];

                object constant = GetConstant(csRow.Value, csRow.Type);

                IHasConstant owner = null;
                switch (csRow.Parent.TokenType)
                {
                case TokenType.Field:
                    owner = GetFieldDefAt(csRow.Parent.RID);
                    break;

                case TokenType.Property:
                    owner = GetPropertyDefAt(csRow.Parent.RID);
                    break;

                case TokenType.Param:
                    owner = GetParamDefAt(csRow.Parent.RID);
                    break;
                }

                owner.Constant = constant;
            }
        }
Example #2
0
            public int Compare(object x, object y)
            {
                ConstantRow a = x as ConstantRow;
                ConstantRow b = y as ConstantRow;

                return(Comparer.Default.Compare(
                           Utilities.CompressMetadataToken(CodedIndex.HasConstant, a.Parent),
                           Utilities.CompressMetadataToken(CodedIndex.HasConstant, b.Parent)));
            }
Example #3
0
        /// <summary>
        /// Creates a constant from a constant metadata row.
        /// </summary>
        /// <param name="parentModule">The module that contains the constant.</param>
        /// <param name="token">The token to initialize the constant for.</param>
        /// <param name="row">The metadata table row to base the constant on.</param>
        public SerializedConstant(SerializedModuleDefinition parentModule, MetadataToken token,
                                  ConstantRow row)
            : base(token)
        {
            _parentModule = parentModule ?? throw new ArgumentNullException(nameof(parentModule));
            _row          = row;

            Type = row.Type;
        }
Example #4
0
 public override void FromRawData(byte [] buff, int offs, int numRows)
 {
     for (int i = numRows; --i >= 0;)
     {
         Row row = new ConstantRow(this);
         row.FromRawData(buff, offs);
         Add(row);
         offs += ConstantRow.LogicalSize;
     }
 }
Example #5
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 ConstantRow result)
        {
            if ((token & TokenTypes.TableMask) != TokenTypes.Constant)
            {
                throw new ArgumentException("Invalid token type for ConstantRow.", "token");
            }

            using (BinaryReader reader = CreateReaderForToken(token))
            {
                CilElementType cet = (CilElementType)reader.ReadByte();
                reader.ReadByte();

                result = new ConstantRow(cet, ReadIndexValue(reader, IndexType.HasConstant), ReadIndexValue(reader, IndexType.BlobHeap));
            }
        }
Example #6
0
        private void AddConstant(MetadataToken ownerToken, Constant constant)
        {
            if (constant is null)
            {
                return;
            }

            var table   = Metadata.TablesStream.GetSortedTable <Constant, ConstantRow>(TableIndex.Constant);
            var encoder = Metadata.TablesStream.GetIndexEncoder(CodedIndex.HasConstant);

            var row = new ConstantRow(
                constant.Type,
                encoder.EncodeToken(ownerToken),
                Metadata.BlobStream.GetBlobIndex(this, constant.Value, DiagnosticBag));

            table.Add(constant, row);
        }
 public virtual void VisitConstantRow(ConstantRow row)
 {
 }
Example #8
0
        void IMetadataProvider.Read(TokenTypes token, out ConstantRow result)
        {
            TableHeap theap = (TableHeap)_streams[(int)HeapType.Tables];

            theap.Read(token, out result);
        }
 public virtual void VisitConstantRow(ConstantRow row)
 {
 }