< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 98
Coverable lines: 98
Total lines: 217
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 28
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%
GetDeclaringType()100%110%
GetParameters()100%110%
GetGenericParameters()100%110%
GetImport()0%220%
GetCustomAttributes()100%110%
GetDeclarativeSecurityAttributes()100%110%
GetProjectedName()0%220%
GetProjectedFlags()0%660%
GetProjectedImplFlags()0%880%
GetProjectedSignature()100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/MethodDefinition.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.Reflection.Metadata.Ecma335;
 5
 6namespace System.Reflection.Metadata
 7{
 8    public readonly struct MethodDefinition
 9    {
 10        private readonly MetadataReader _reader;
 11
 12        // Workaround: JIT doesn't generate good code for nested structures, so use RowId.
 13        private readonly uint _treatmentAndRowId;
 14
 15        internal MethodDefinition(MetadataReader reader, uint treatmentAndRowId)
 016        {
 017            _reader = reader;
 018            _treatmentAndRowId = treatmentAndRowId;
 019        }
 20
 21        private int RowId
 22        {
 023            get { return (int)(_treatmentAndRowId & TokenTypeIds.RIDMask); }
 24        }
 25
 26        private MethodDefTreatment Treatment
 27        {
 028            get { return (MethodDefTreatment)(_treatmentAndRowId >> TokenTypeIds.RowIdBitCount); }
 29        }
 30
 31        private MethodDefinitionHandle Handle
 32        {
 033            get { return MethodDefinitionHandle.FromRowId(RowId); }
 34        }
 35
 36        public StringHandle Name
 37        {
 38            get
 039            {
 040                if (Treatment == 0)
 041                {
 042                    return _reader.MethodDefTable.GetName(Handle);
 43                }
 44
 045                return GetProjectedName();
 046            }
 47        }
 48
 49        public BlobHandle Signature
 50        {
 51            get
 052            {
 053                if (Treatment == 0)
 054                {
 055                    return _reader.MethodDefTable.GetSignature(Handle);
 56                }
 57
 058                return GetProjectedSignature();
 059            }
 60        }
 61
 62        public MethodSignature<TType> DecodeSignature<TType, TGenericContext>(ISignatureTypeProvider<TType, TGenericCont
 063        {
 064            var decoder = new SignatureDecoder<TType, TGenericContext>(provider, _reader, genericContext);
 065            var blobReader = _reader.GetBlobReader(Signature);
 066            return decoder.DecodeMethodSignature(ref blobReader);
 067        }
 68
 69        public int RelativeVirtualAddress
 70        {
 71            get
 072            {
 073                if (Treatment == 0)
 074                {
 075                    return _reader.MethodDefTable.GetRva(Handle);
 76                }
 77
 78                return GetProjectedRelativeVirtualAddress();
 079            }
 80        }
 81
 82        public MethodAttributes Attributes
 83        {
 84            get
 085            {
 086                if (Treatment == 0)
 087                {
 088                    return _reader.MethodDefTable.GetFlags(Handle);
 89                }
 90
 091                return GetProjectedFlags();
 092            }
 93        }
 94
 95        public MethodImplAttributes ImplAttributes
 96        {
 97            get
 098            {
 099                if (Treatment == 0)
 0100                {
 0101                    return _reader.MethodDefTable.GetImplFlags(Handle);
 102                }
 103
 0104                return GetProjectedImplFlags();
 0105            }
 106        }
 107
 108        /// <summary>
 109        /// Returns a handle to the type that declares this method.
 110        /// </summary>
 111        public TypeDefinitionHandle GetDeclaringType()
 0112        {
 0113            return _reader.GetDeclaringType(Handle);
 0114        }
 115
 116        public ParameterHandleCollection GetParameters()
 0117        {
 0118            return new ParameterHandleCollection(_reader, Handle);
 0119        }
 120
 121        public GenericParameterHandleCollection GetGenericParameters()
 0122        {
 0123            return _reader.GenericParamTable.FindGenericParametersForMethod(Handle);
 0124        }
 125
 126        public MethodImport GetImport()
 0127        {
 0128            int implMapRid = _reader.ImplMapTable.FindImplForMethod(Handle);
 0129            if (implMapRid == 0)
 0130            {
 0131                return default(MethodImport);
 132            }
 133
 0134            return _reader.ImplMapTable.GetImport(implMapRid);
 0135        }
 136
 137        public CustomAttributeHandleCollection GetCustomAttributes()
 0138        {
 0139            return new CustomAttributeHandleCollection(_reader, Handle);
 0140        }
 141
 142        public DeclarativeSecurityAttributeHandleCollection GetDeclarativeSecurityAttributes()
 0143        {
 0144            return new DeclarativeSecurityAttributeHandleCollection(_reader, Handle);
 0145        }
 146
 147#region Projections
 148
 149        private StringHandle GetProjectedName()
 0150        {
 0151            if ((Treatment & MethodDefTreatment.KindMask) == MethodDefTreatment.DisposeMethod)
 0152            {
 0153                return StringHandle.FromVirtualIndex(StringHandle.VirtualIndex.Dispose);
 154            }
 155
 0156            return _reader.MethodDefTable.GetName(Handle);
 0157        }
 158
 159        private MethodAttributes GetProjectedFlags()
 0160        {
 0161            MethodAttributes flags = _reader.MethodDefTable.GetFlags(Handle);
 0162            MethodDefTreatment treatment = Treatment;
 163
 0164            if ((treatment & MethodDefTreatment.KindMask) == MethodDefTreatment.HiddenInterfaceImplementation)
 0165            {
 0166                flags = (flags & ~MethodAttributes.MemberAccessMask) | MethodAttributes.Private;
 0167            }
 168
 0169            if ((treatment & MethodDefTreatment.MarkAbstractFlag) != 0)
 0170            {
 0171                flags |= MethodAttributes.Abstract;
 0172            }
 173
 0174            if ((treatment & MethodDefTreatment.MarkPublicFlag) != 0)
 0175            {
 0176                flags = (flags & ~MethodAttributes.MemberAccessMask) | MethodAttributes.Public;
 0177            }
 178
 179
 0180            return flags | MethodAttributes.HideBySig;
 0181        }
 182
 183        private MethodImplAttributes GetProjectedImplFlags()
 0184        {
 0185            MethodImplAttributes flags = _reader.MethodDefTable.GetImplFlags(Handle);
 186
 0187            switch (Treatment & MethodDefTreatment.KindMask)
 188            {
 189                case MethodDefTreatment.DelegateMethod:
 0190                    flags |= MethodImplAttributes.Runtime;
 0191                    break;
 192
 193                case MethodDefTreatment.DisposeMethod:
 194                case MethodDefTreatment.AttributeMethod:
 195                case MethodDefTreatment.InterfaceMethod:
 196                case MethodDefTreatment.HiddenInterfaceImplementation:
 197                case MethodDefTreatment.Other:
 0198                    flags |= MethodImplAttributes.Runtime | MethodImplAttributes.InternalCall;
 0199                    break;
 200            }
 201
 0202            return flags;
 0203        }
 204
 205        private BlobHandle GetProjectedSignature()
 0206        {
 0207            return _reader.MethodDefTable.GetSignature(Handle);
 0208        }
 209
 210        private static int GetProjectedRelativeVirtualAddress()
 211        {
 212            return 0;
 213        }
 214#endregion
 215    }
 216}
 217