public ConstantEntry(MetadataDirectory directory, ConstantMetadataTableRow row)
 {
     this.FileOffset = string.Format("0x{0:x}", row.FileOffset);
     this.Parent     = row.Parent.ToString();
     this.Type       = row.Type.ToString();
     this.Value      = string.Format("0x{0:x}", row.Value);
 }
        private void LoadConstantMetadata()
        {
            if (!_stream.Tables.ContainsKey(MetadataTables.Constant))
            {
                return;
            }

            MetadataRow[] constants = _stream.Tables[MetadataTables.Constant];

            for (int i = 0; i < constants.Length; i++)
            {
                ConstantMetadataTableRow constantRow = constants[i] as ConstantMetadataTableRow;
                ConstantInfo             constant    = ConstantInfo.CreateFromMetadata(_assembly, _stream, constantRow);

                switch (constantRow.Parent.Table)
                {
                case MetadataTables.Field:
                    FieldDef field = _map.GetDefinition(MetadataTables.Field,
                                                        _stream.GetEntryFor(MetadataTables.Field, constantRow.Parent.Index)
                                                        ) as FieldDef;
                    field.Constants.Add(constant);
                    break;

                case MetadataTables.Property:
                    break;

                case MetadataTables.Param:
                    ParamDef parameter = _map.GetDefinition(MetadataTables.Param,
                                                            _stream.GetEntryFor(MetadataTables.Param, constantRow.Parent.Index)
                                                            ) as ParamDef;
                    parameter.Constants.Add(constant);
                    break;
                }
            }
        }
        public void Constant_WhenCreated_OffsetIsMovedOn()
        {
            ICodedIndexResolver resolver     = IndexHelper.CreateCodedIndexResolver(2);
            IIndexDetails       indexDetails = IndexHelper.CreateIndexDetails(2);
            Offset offset = 0;

            byte[] content = new byte[30];

            ConstantMetadataTableRow row = new ConstantMetadataTableRow(content, offset, resolver, indexDetails);

            Assert.AreEqual(6, offset.Current);
        }
        public void Constant_WhenCreated_ValuesAreReadCorrectly()
        {
            ICodedIndexResolver resolver     = IndexHelper.CreateCodedIndexResolver(2);
            IIndexDetails       indexDetails = IndexHelper.CreateIndexDetails(2);

            byte[] content = new byte[] {
                0x01,
                0x00,
                0x05, 0x00,
                0x00, 0x00
            };

            ConstantMetadataTableRow row = new ConstantMetadataTableRow(content, 0, resolver, indexDetails);

            Assert.AreEqual(Reflection.Signatures.ElementTypes.Void, row.Type);
            Assert.IsNotNull(row.Parent);
            Assert.AreEqual(0, row.Value.Value);
        }
Ejemplo n.º 5
0
        public static ConstantInfo CreateFromMetadata(AssemblyDef assembly, MetadataStream stream, ConstantMetadataTableRow row)
        {
            // we are not doing anything with this at the moment but it stores the details of constants
            // indirectly via the BlobIndex, it's parent is obtainable via a HasConstant CodedIndex in
            // the metadata row.
            // The values here are for fields and parameters, so we can say that the default values for
            // parameters are accessible via these records.

            return(new ConstantInfo());
        }