| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | namespace System.Reflection.Metadata |
| | | 5 | | { |
| | | 6 | | public readonly struct Constant |
| | | 7 | | { |
| | | 8 | | private readonly MetadataReader _reader; |
| | | 9 | | |
| | | 10 | | // Workaround: JIT doesn't generate good code for nested structures, so use RowId. |
| | | 11 | | private readonly int _rowId; |
| | | 12 | | |
| | | 13 | | internal Constant(MetadataReader reader, int rowId) |
| | 0 | 14 | | { |
| | 0 | 15 | | _reader = reader; |
| | 0 | 16 | | _rowId = rowId; |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | private ConstantHandle Handle |
| | | 20 | | { |
| | | 21 | | get |
| | 0 | 22 | | { |
| | 0 | 23 | | return ConstantHandle.FromRowId(_rowId); |
| | 0 | 24 | | } |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// The type of the constant value. |
| | | 29 | | /// </summary> |
| | | 30 | | /// <remarks> |
| | | 31 | | /// Corresponds to Type field of Constant table in ECMA-335 Standard. |
| | | 32 | | /// </remarks> |
| | | 33 | | public ConstantTypeCode TypeCode |
| | | 34 | | { |
| | | 35 | | get |
| | 0 | 36 | | { |
| | 0 | 37 | | return _reader.ConstantTable.GetType(Handle); |
| | 0 | 38 | | } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// The constant value. |
| | | 43 | | /// </summary> |
| | | 44 | | /// <remarks> |
| | | 45 | | /// Corresponds to Value field of Constant table in ECMA-335 Standard. |
| | | 46 | | /// </remarks> |
| | | 47 | | public BlobHandle Value |
| | | 48 | | { |
| | | 49 | | get |
| | 0 | 50 | | { |
| | 0 | 51 | | return _reader.ConstantTable.GetValue(Handle); |
| | 0 | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// The parent handle (<see cref="ParameterHandle"/>, <see cref="FieldDefinitionHandle"/>, or <see cref="Propert |
| | | 57 | | /// </summary> |
| | | 58 | | /// <remarks> |
| | | 59 | | /// Corresponds to Parent field of Constant table in ECMA-335 Standard. |
| | | 60 | | /// </remarks> |
| | | 61 | | public EntityHandle Parent |
| | | 62 | | { |
| | | 63 | | get |
| | 0 | 64 | | { |
| | 0 | 65 | | return _reader.ConstantTable.GetParent(Handle); |
| | 0 | 66 | | } |
| | | 67 | | } |
| | | 68 | | } |
| | | 69 | | } |
| | | 70 | | |