< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 48
Coverable lines: 48
Total lines: 110
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 11
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
DecodeSignature(...)100%110%
GetDefaultValue()100%110%
GetCustomAttributes()100%110%
GetDeclaringType()100%110%
GetAccessors()0%11110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/PropertyDefinition.cs

#LineLine coverage
 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
 4using System.Collections.Immutable;
 5using System.Reflection.Metadata.Ecma335;
 6
 7namespace 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)
 017        {
 018            _reader = reader;
 019            _rowId = handle.RowId;
 020        }
 21
 22        private PropertyDefinitionHandle Handle
 23        {
 024            get { return PropertyDefinitionHandle.FromRowId(_rowId); }
 25        }
 26
 27        public StringHandle Name
 28        {
 29            get
 030            {
 031                return _reader.PropertyTable.GetName(Handle);
 032            }
 33        }
 34
 35        public PropertyAttributes Attributes
 36        {
 37            get
 038            {
 039                return _reader.PropertyTable.GetFlags(Handle);
 040            }
 41        }
 42
 43        public BlobHandle Signature
 44        {
 45            get
 046            {
 047                return _reader.PropertyTable.GetSignature(Handle);
 048            }
 49        }
 50
 51        public MethodSignature<TType> DecodeSignature<TType, TGenericContext>(ISignatureTypeProvider<TType, TGenericCont
 052        {
 053            var decoder = new SignatureDecoder<TType, TGenericContext>(provider, _reader, genericContext);
 054            var blobReader = _reader.GetBlobReader(Signature);
 055            return decoder.DecodeMethodSignature(ref blobReader);
 056        }
 57
 58        public ConstantHandle GetDefaultValue()
 059        {
 060            return _reader.ConstantTable.FindConstant(Handle);
 061        }
 62
 63        public CustomAttributeHandleCollection GetCustomAttributes()
 064        {
 065            return new CustomAttributeHandleCollection(_reader, Handle);
 066        }
 67
 68        /// <summary>
 69        /// Returns a handle to the type that declares this property.
 70        /// </summary>
 71        public TypeDefinitionHandle GetDeclaringType()
 072        {
 073            return _reader.GetDeclaringType(Handle);
 074        }
 75
 76        public PropertyAccessors GetAccessors()
 077        {
 078            int getter = 0;
 079            int setter = 0;
 080            ImmutableArray<MethodDefinitionHandle>.Builder? other = null;
 81
 82            ushort methodCount;
 083            int firstRowId = _reader.MethodSemanticsTable.FindSemanticMethodsForProperty(Handle, out methodCount);
 084            for (ushort i = 0; i < methodCount; i++)
 085            {
 086                int rowId = firstRowId + i;
 087                switch (_reader.MethodSemanticsTable.GetSemantics(rowId))
 88                {
 89                    case MethodSemanticsAttributes.Getter:
 090                        getter = _reader.MethodSemanticsTable.GetMethod(rowId).RowId;
 091                        break;
 92
 93                    case MethodSemanticsAttributes.Setter:
 094                        setter = _reader.MethodSemanticsTable.GetMethod(rowId).RowId;
 095                        break;
 96
 97                    case MethodSemanticsAttributes.Other:
 098                        other ??= ImmutableArray.CreateBuilder<MethodDefinitionHandle>();
 99
 0100                        other.Add(_reader.MethodSemanticsTable.GetMethod(rowId));
 0101                        break;
 102                }
 0103            }
 104
 0105            var otherAccessors = other?.ToImmutable() ?? ImmutableArray<MethodDefinitionHandle>.Empty;
 0106            return new PropertyAccessors(getter, setter, otherAccessors);
 0107        }
 108    }
 109}
 110