| | | 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 | | using System.Collections.Immutable; |
| | | 5 | | using System.Reflection.Metadata.Ecma335; |
| | | 6 | | |
| | | 7 | | namespace System.Reflection.Metadata |
| | | 8 | | { |
| | | 9 | | public readonly struct PropertyDefinition |
| | | 10 | | { |
| | | 11 | | private readonly MetadataReader _reader; |
| | | 12 | | |
| | | 13 | | // Workaround: JIT doesn't generate good code for nested structures, so use RowId. |
| | | 14 | | private readonly int _rowId; |
| | | 15 | | |
| | | 16 | | internal PropertyDefinition(MetadataReader reader, PropertyDefinitionHandle handle) |
| | 0 | 17 | | { |
| | 0 | 18 | | _reader = reader; |
| | 0 | 19 | | _rowId = handle.RowId; |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | private PropertyDefinitionHandle Handle |
| | | 23 | | { |
| | 0 | 24 | | get { return PropertyDefinitionHandle.FromRowId(_rowId); } |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | public StringHandle Name |
| | | 28 | | { |
| | | 29 | | get |
| | 0 | 30 | | { |
| | 0 | 31 | | return _reader.PropertyTable.GetName(Handle); |
| | 0 | 32 | | } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public PropertyAttributes Attributes |
| | | 36 | | { |
| | | 37 | | get |
| | 0 | 38 | | { |
| | 0 | 39 | | return _reader.PropertyTable.GetFlags(Handle); |
| | 0 | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | public BlobHandle Signature |
| | | 44 | | { |
| | | 45 | | get |
| | 0 | 46 | | { |
| | 0 | 47 | | return _reader.PropertyTable.GetSignature(Handle); |
| | 0 | 48 | | } |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public MethodSignature<TType> DecodeSignature<TType, TGenericContext>(ISignatureTypeProvider<TType, TGenericCont |
| | 0 | 52 | | { |
| | 0 | 53 | | var decoder = new SignatureDecoder<TType, TGenericContext>(provider, _reader, genericContext); |
| | 0 | 54 | | var blobReader = _reader.GetBlobReader(Signature); |
| | 0 | 55 | | return decoder.DecodeMethodSignature(ref blobReader); |
| | 0 | 56 | | } |
| | | 57 | | |
| | | 58 | | public ConstantHandle GetDefaultValue() |
| | 0 | 59 | | { |
| | 0 | 60 | | return _reader.ConstantTable.FindConstant(Handle); |
| | 0 | 61 | | } |
| | | 62 | | |
| | | 63 | | public CustomAttributeHandleCollection GetCustomAttributes() |
| | 0 | 64 | | { |
| | 0 | 65 | | return new CustomAttributeHandleCollection(_reader, Handle); |
| | 0 | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Returns a handle to the type that declares this property. |
| | | 70 | | /// </summary> |
| | | 71 | | public TypeDefinitionHandle GetDeclaringType() |
| | 0 | 72 | | { |
| | 0 | 73 | | return _reader.GetDeclaringType(Handle); |
| | 0 | 74 | | } |
| | | 75 | | |
| | | 76 | | public PropertyAccessors GetAccessors() |
| | 0 | 77 | | { |
| | 0 | 78 | | int getter = 0; |
| | 0 | 79 | | int setter = 0; |
| | 0 | 80 | | ImmutableArray<MethodDefinitionHandle>.Builder? other = null; |
| | | 81 | | |
| | | 82 | | ushort methodCount; |
| | 0 | 83 | | int firstRowId = _reader.MethodSemanticsTable.FindSemanticMethodsForProperty(Handle, out methodCount); |
| | 0 | 84 | | for (ushort i = 0; i < methodCount; i++) |
| | 0 | 85 | | { |
| | 0 | 86 | | int rowId = firstRowId + i; |
| | 0 | 87 | | switch (_reader.MethodSemanticsTable.GetSemantics(rowId)) |
| | | 88 | | { |
| | | 89 | | case MethodSemanticsAttributes.Getter: |
| | 0 | 90 | | getter = _reader.MethodSemanticsTable.GetMethod(rowId).RowId; |
| | 0 | 91 | | break; |
| | | 92 | | |
| | | 93 | | case MethodSemanticsAttributes.Setter: |
| | 0 | 94 | | setter = _reader.MethodSemanticsTable.GetMethod(rowId).RowId; |
| | 0 | 95 | | break; |
| | | 96 | | |
| | | 97 | | case MethodSemanticsAttributes.Other: |
| | 0 | 98 | | other ??= ImmutableArray.CreateBuilder<MethodDefinitionHandle>(); |
| | | 99 | | |
| | 0 | 100 | | other.Add(_reader.MethodSemanticsTable.GetMethod(rowId)); |
| | 0 | 101 | | break; |
| | | 102 | | } |
| | 0 | 103 | | } |
| | | 104 | | |
| | 0 | 105 | | var otherAccessors = other?.ToImmutable() ?? ImmutableArray<MethodDefinitionHandle>.Empty; |
| | 0 | 106 | | return new PropertyAccessors(getter, setter, otherAccessors); |
| | 0 | 107 | | } |
| | | 108 | | } |
| | | 109 | | } |
| | | 110 | | |