< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 45
Coverable lines: 45
Total lines: 135
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%
op_Implicit(...)100%110%
op_Explicit(...)0%220%
Equals(...)0%220%
Equals(...)100%110%
GetHashCode()100%110%
op_Equality(...)100%110%
op_Inequality(...)100%110%
Compare(...)100%110%
.cctor()100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/EntityHandle.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.Diagnostics.CodeAnalysis;
 6using System.Reflection.Metadata.Ecma335;
 7
 8namespace System.Reflection.Metadata
 9{
 10    /// <summary>
 11    /// Represents a metadata entity (type reference/definition/specification, method definition, custom attribute, etc.
 12    /// </summary>
 13    /// <remarks>
 14    /// Use <see cref="EntityHandle"/> to store multiple kinds of entity handles.
 15    /// It has smaller memory footprint than <see cref="Handle"/>.
 16    /// </remarks>
 17    public readonly struct EntityHandle : IEquatable<EntityHandle>
 18    {
 19        // bits:
 20        //     31: IsVirtual
 21        // 24..30: type
 22        //  0..23: row id
 23        private readonly uint _vToken;
 24
 25        internal EntityHandle(uint vToken)
 026        {
 027            _vToken = vToken;
 028        }
 29
 30        public static implicit operator Handle(EntityHandle handle)
 031        {
 032            return Handle.FromVToken(handle._vToken);
 033        }
 34
 35        public static explicit operator EntityHandle(Handle handle)
 036        {
 037            if (handle.IsHeapHandle)
 038            {
 039                Throw.InvalidCast();
 40            }
 41
 042            return new EntityHandle(handle.EntityHandleValue);
 043        }
 44
 45        internal uint Type
 46        {
 047            get { return _vToken & TokenTypeIds.TypeMask; }
 48        }
 49
 50        internal uint VType
 51        {
 052            get { return _vToken & (TokenTypeIds.VirtualBit | TokenTypeIds.TypeMask); }
 53        }
 54
 55        internal bool IsVirtual
 56        {
 057            get { return (_vToken & TokenTypeIds.VirtualBit) != 0; }
 58        }
 59
 60        public bool IsNil
 61        {
 62            // virtual handle is never nil
 063            get { return (_vToken & (TokenTypeIds.VirtualBit | TokenTypeIds.RIDMask)) == 0; }
 64        }
 65
 66        internal int RowId
 67        {
 068            get { return (int)(_vToken & TokenTypeIds.RIDMask); }
 69        }
 70
 71        /// <summary>
 72        /// Value stored in a specific entity handle (see <see cref="TypeDefinitionHandle"/>, <see cref="MethodDefinitio
 73        /// </summary>
 74        internal uint SpecificHandleValue
 75        {
 076            get { return _vToken & (TokenTypeIds.VirtualBit | TokenTypeIds.RIDMask); }
 77        }
 78
 79        public HandleKind Kind
 80        {
 81            get
 082            {
 83                // EntityHandles cannot be StringHandles and therefore we do not need
 84                // to handle stripping the extra non-virtual string type bits here.
 085                return (HandleKind)(Type >> TokenTypeIds.RowIdBitCount);
 086            }
 87        }
 88
 89        internal int Token
 90        {
 91            get
 092            {
 093                Debug.Assert(!IsVirtual);
 094                return (int)_vToken;
 095            }
 96        }
 97
 98        public override bool Equals([NotNullWhen(true)] object? obj)
 099        {
 0100            return obj is EntityHandle entityHandle && Equals(entityHandle);
 0101        }
 102
 103        public bool Equals(EntityHandle other)
 0104        {
 0105            return _vToken == other._vToken;
 0106        }
 107
 108        public override int GetHashCode()
 0109        {
 0110            return unchecked((int)_vToken);
 0111        }
 112
 113        public static bool operator ==(EntityHandle left, EntityHandle right)
 0114        {
 0115            return left.Equals(right);
 0116        }
 117
 118        public static bool operator !=(EntityHandle left, EntityHandle right)
 0119        {
 0120            return !left.Equals(right);
 0121        }
 122
 123        internal static int Compare(EntityHandle left, EntityHandle right)
 0124        {
 125            // All virtual tokens will be sorted after non-virtual tokens.
 126            // The order of handles that differ in kind is undefined,
 127            // but we include it so that we ensure consistency with == and != operators.
 0128            return left._vToken.CompareTo(right._vToken);
 0129        }
 130
 0131        public static readonly ModuleDefinitionHandle ModuleDefinition = new ModuleDefinitionHandle(1);
 0132        public static readonly AssemblyDefinitionHandle AssemblyDefinition = new AssemblyDefinitionHandle(1);
 133    }
 134}
 135