< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 57
Coverable lines: 57
Total lines: 168
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
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%
GetProjectedResolutionScope()0%440%
GetProjectedName()0%220%
GetProjectedNamespace()0%440%
GetProjectedSignatureTreatment()0%220%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/TypeReference.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.Diagnostics;
 5using System.Reflection.Metadata.Ecma335;
 6
 7namespace System.Reflection.Metadata
 8{
 9    public readonly struct TypeReference
 10    {
 11        private readonly MetadataReader _reader;
 12
 13        // Workaround: JIT doesn't generate good code for nested structures, so use RowId.
 14        private readonly uint _treatmentAndRowId;
 15
 16        internal TypeReference(MetadataReader reader, uint treatmentAndRowId)
 017        {
 018            _reader = reader;
 019            _treatmentAndRowId = treatmentAndRowId;
 020        }
 21
 22        private int RowId
 23        {
 024            get { return (int)(_treatmentAndRowId & TokenTypeIds.RIDMask); }
 25        }
 26
 27        private TypeRefTreatment Treatment
 28        {
 029            get { return (TypeRefTreatment)(_treatmentAndRowId >> TokenTypeIds.RowIdBitCount); }
 30        }
 31
 32        private TypeReferenceHandle Handle
 33        {
 034            get { return TypeReferenceHandle.FromRowId(RowId); }
 35        }
 36
 37        /// <summary>
 38        /// Resolution scope in which the target type is defined and is uniquely identified by the specified <see cref="
 39        /// </summary>
 40        /// <remarks>
 41        /// Resolution scope can be one of the following handles:
 42        /// <list type="bullet">
 43        /// <item><description><see cref="TypeReferenceHandle"/> of the enclosing type, if the target type is a nested t
 44        /// <item><description><see cref="ModuleReferenceHandle"/>, if the target type is defined in another module with
 45        /// <item><description><see cref="EntityHandle.ModuleDefinition"/>, if the target type is defined in the current
 46        /// <item><description><see cref="AssemblyReferenceHandle"/>, if the target type is defined in a different assem
 47        /// <item><description>Nil handle if the target type must be resolved by searching the <see cref="MetadataReader
 48        /// </list>
 49        /// </remarks>
 50        public EntityHandle ResolutionScope
 51        {
 52            get
 053            {
 054                if (Treatment == 0)
 055                {
 056                    return _reader.TypeRefTable.GetResolutionScope(Handle);
 57                }
 58
 059                return GetProjectedResolutionScope();
 060            }
 61        }
 62
 63        /// <summary>
 64        /// Name of the target type.
 65        /// </summary>
 66        public StringHandle Name
 67        {
 68            get
 069            {
 070                if (Treatment == 0)
 071                {
 072                    return _reader.TypeRefTable.GetName(Handle);
 73                }
 74
 075                return GetProjectedName();
 076            }
 77        }
 78
 79        /// <summary>
 80        /// Full name of the namespace where the target type is defined, or nil if the type is nested or defined in a ro
 81        /// </summary>
 82        public StringHandle Namespace
 83        {
 84            get
 085            {
 086                if (Treatment == 0)
 087                {
 088                    return _reader.TypeRefTable.GetNamespace(Handle);
 89                }
 90
 091                return GetProjectedNamespace();
 092            }
 93        }
 94
 95        #region Projections
 96
 97        private EntityHandle GetProjectedResolutionScope()
 098        {
 099            switch (Treatment)
 100            {
 101                case TypeRefTreatment.SystemAttribute:
 102                case TypeRefTreatment.SystemDelegate:
 0103                    return AssemblyReferenceHandle.FromVirtualIndex(AssemblyReferenceHandle.VirtualIndex.System_Runtime)
 104
 105                case TypeRefTreatment.UseProjectionInfo:
 0106                    return MetadataReader.GetProjectedAssemblyRef(RowId);
 107            }
 108
 0109            Debug.Fail("Unknown TypeRef treatment");
 110            return default(AssemblyReferenceHandle);
 0111        }
 112
 113        private StringHandle GetProjectedName()
 0114        {
 0115            if (Treatment == TypeRefTreatment.UseProjectionInfo)
 0116            {
 0117                return MetadataReader.GetProjectedName(RowId);
 118            }
 119            else
 0120            {
 0121                return _reader.TypeRefTable.GetName(Handle);
 122            }
 0123        }
 124
 125        private StringHandle GetProjectedNamespace()
 0126        {
 0127            switch (Treatment)
 128            {
 129                case TypeRefTreatment.SystemAttribute:
 130                case TypeRefTreatment.SystemDelegate:
 0131                    return StringHandle.FromVirtualIndex(StringHandle.VirtualIndex.System);
 132
 133                case TypeRefTreatment.UseProjectionInfo:
 0134                    return MetadataReader.GetProjectedNamespace(RowId);
 135            }
 136
 0137            Debug.Fail("Unknown TypeRef treatment");
 138            return default(StringHandle);
 0139        }
 140
 141        internal TypeRefSignatureTreatment SignatureTreatment
 142        {
 143            get
 0144            {
 0145                if (Treatment == 0)
 0146                {
 0147                    return TypeRefSignatureTreatment.None;
 148                }
 149
 0150                return GetProjectedSignatureTreatment();
 0151            }
 152        }
 153
 154        private TypeRefSignatureTreatment GetProjectedSignatureTreatment()
 0155        {
 0156            if (Treatment == TypeRefTreatment.UseProjectionInfo)
 0157            {
 0158                return MetadataReader.GetProjectedSignatureTreatment(RowId);
 159            }
 160            else
 0161            {
 0162                return TypeRefSignatureTreatment.None;
 163            }
 0164        }
 165        #endregion
 166    }
 167}
 168