< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 92
Coverable lines: 92
Total lines: 232
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 27
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/AssemblyReference.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 partial struct AssemblyReference
 10    {
 11        private readonly MetadataReader _reader;
 12
 13        // Workaround: JIT doesn't generate good code for nested structures, so use raw uint.
 14        private readonly uint _treatmentAndRowId;
 15
 016        private static readonly Version s_version_4_0_0_0 = new Version(4, 0, 0, 0);
 17
 18        internal AssemblyReference(MetadataReader reader, uint treatmentAndRowId)
 019        {
 020            _reader = reader;
 021            _treatmentAndRowId = treatmentAndRowId;
 022        }
 23
 24        private int RowId
 25        {
 026            get { return (int)(_treatmentAndRowId & TokenTypeIds.RIDMask); }
 27        }
 28
 29        private bool IsVirtual
 30        {
 031            get { return (_treatmentAndRowId & TokenTypeIds.VirtualBit) != 0; }
 32        }
 33
 34        public Version Version
 35        {
 36            get
 037            {
 038                if (IsVirtual)
 039                {
 040                    return GetVirtualVersion();
 41                }
 42
 43                // change mscorlib version:
 044                if (RowId == _reader.WinMDMscorlibRef)
 045                {
 046                    return s_version_4_0_0_0;
 47                }
 48
 049                return _reader.AssemblyRefTable.GetVersion(RowId);
 050            }
 51        }
 52
 53        public AssemblyFlags Flags
 54        {
 55            get
 056            {
 057                if (IsVirtual)
 058                {
 059                    return GetVirtualFlags();
 60                }
 61
 062                return _reader.AssemblyRefTable.GetFlags(RowId);
 063            }
 64        }
 65
 66        public StringHandle Name
 67        {
 68            get
 069            {
 070                if (IsVirtual)
 071                {
 072                    return GetVirtualName();
 73                }
 74
 075                return _reader.AssemblyRefTable.GetName(RowId);
 076            }
 77        }
 78
 79        public StringHandle Culture
 80        {
 81            get
 082            {
 083                if (IsVirtual)
 084                {
 085                    return GetVirtualCulture();
 86                }
 87
 088                return _reader.AssemblyRefTable.GetCulture(RowId);
 089            }
 90        }
 91
 92        public BlobHandle PublicKeyOrToken
 93        {
 94            get
 095            {
 096                if (IsVirtual)
 097                {
 098                    return GetVirtualPublicKeyOrToken();
 99                }
 100
 0101                return _reader.AssemblyRefTable.GetPublicKeyOrToken(RowId);
 0102            }
 103        }
 104
 105        public BlobHandle HashValue
 106        {
 107            get
 0108            {
 0109                if (IsVirtual)
 0110                {
 0111                    return GetVirtualHashValue();
 112                }
 113
 0114                return _reader.AssemblyRefTable.GetHashValue(RowId);
 0115            }
 116        }
 117
 118        public CustomAttributeHandleCollection GetCustomAttributes()
 0119        {
 0120            if (IsVirtual)
 0121            {
 0122                return GetVirtualCustomAttributes();
 123            }
 124
 0125            return new CustomAttributeHandleCollection(_reader, AssemblyReferenceHandle.FromRowId(RowId));
 0126        }
 127
 128        #region Virtual Rows
 129        private static Version GetVirtualVersion()
 0130        {
 131            // currently all projected assembly references have version 4.0.0.0
 0132            return s_version_4_0_0_0;
 0133        }
 134
 135        private AssemblyFlags GetVirtualFlags()
 0136        {
 137            // use flags from mscorlib ref (specifically PublicKey flag):
 0138            return _reader.AssemblyRefTable.GetFlags(_reader.WinMDMscorlibRef);
 0139        }
 140
 141        private StringHandle GetVirtualName()
 0142        {
 0143            return StringHandle.FromVirtualIndex(GetVirtualNameIndex((AssemblyReferenceHandle.VirtualIndex)RowId));
 0144        }
 145
 146        private static StringHandle.VirtualIndex GetVirtualNameIndex(AssemblyReferenceHandle.VirtualIndex index)
 0147        {
 0148            switch (index)
 149            {
 150                case AssemblyReferenceHandle.VirtualIndex.System_ObjectModel:
 0151                    return StringHandle.VirtualIndex.System_ObjectModel;
 152
 153                case AssemblyReferenceHandle.VirtualIndex.System_Runtime:
 0154                    return StringHandle.VirtualIndex.System_Runtime;
 155
 156                case AssemblyReferenceHandle.VirtualIndex.System_Runtime_InteropServices_WindowsRuntime:
 0157                    return StringHandle.VirtualIndex.System_Runtime_InteropServices_WindowsRuntime;
 158
 159                case AssemblyReferenceHandle.VirtualIndex.System_Runtime_WindowsRuntime:
 0160                    return StringHandle.VirtualIndex.System_Runtime_WindowsRuntime;
 161
 162                case AssemblyReferenceHandle.VirtualIndex.System_Runtime_WindowsRuntime_UI_Xaml:
 0163                    return StringHandle.VirtualIndex.System_Runtime_WindowsRuntime_UI_Xaml;
 164
 165                case AssemblyReferenceHandle.VirtualIndex.System_Numerics_Vectors:
 0166                    return StringHandle.VirtualIndex.System_Numerics_Vectors;
 167            }
 168
 0169            Debug.Fail("Unexpected virtual index value");
 170            return 0;
 0171        }
 172
 173        private static StringHandle GetVirtualCulture()
 0174        {
 0175            return default(StringHandle);
 0176        }
 177
 178        private BlobHandle GetVirtualPublicKeyOrToken()
 0179        {
 0180            switch ((AssemblyReferenceHandle.VirtualIndex)RowId)
 181            {
 182                case AssemblyReferenceHandle.VirtualIndex.System_Runtime_WindowsRuntime:
 183                case AssemblyReferenceHandle.VirtualIndex.System_Runtime_WindowsRuntime_UI_Xaml:
 184                    // use key or token from mscorlib ref:
 0185                    return _reader.AssemblyRefTable.GetPublicKeyOrToken(_reader.WinMDMscorlibRef);
 186
 187                default:
 188                    // use contract assembly key or token:
 0189                    var hasFullKey = (_reader.AssemblyRefTable.GetFlags(_reader.WinMDMscorlibRef) & AssemblyFlags.Public
 0190                    return BlobHandle.FromVirtualIndex(hasFullKey ? BlobHandle.VirtualIndex.ContractPublicKey : BlobHand
 191            }
 0192        }
 193
 194        private static BlobHandle GetVirtualHashValue()
 0195        {
 0196            return default(BlobHandle);
 0197        }
 198
 199        private CustomAttributeHandleCollection GetVirtualCustomAttributes()
 0200        {
 201            // return custom attributes applied on mscorlib ref
 0202            return new CustomAttributeHandleCollection(_reader, AssemblyReferenceHandle.FromRowId(_reader.WinMDMscorlibR
 0203        }
 204        #endregion
 205    }
 206}
 207

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/AssemblyReference.netstandard.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
 4namespace System.Reflection.Metadata
 5{
 6    public readonly partial struct AssemblyReference
 7    {
 8        /// <summary>
 9        /// Creates an <see cref="AssemblyName"/> instance corresponding to this assembly reference.
 10        /// </summary>
 11        public AssemblyName GetAssemblyName()
 012        {
 013            return _reader.GetAssemblyName(Name, Version, Culture, PublicKeyOrToken, AssemblyHashAlgorithm.None, Flags);
 014        }
 15
 16        /// <summary>
 17        /// Creates an <see cref="AssemblyNameInfo"/> instance corresponding to this assembly reference.
 18        /// </summary>
 19        public AssemblyNameInfo GetAssemblyNameInfo()
 020        {
 021            return _reader.GetAssemblyNameInfo(Name, Version, Culture, PublicKeyOrToken, Flags);
 022        }
 23    }
 24}
 25