| | | 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 | | |
| | | 4 | | using System.Runtime.CompilerServices; |
| | | 5 | | |
| | | 6 | | namespace System.Reflection.Metadata.Ecma335 |
| | | 7 | | { |
| | | 8 | | internal static class TypeOrMethodDefTag |
| | | 9 | | { |
| | | 10 | | internal const int NumberOfBits = 1; |
| | | 11 | | internal const int LargeRowSize = 0x00000001 << (16 - NumberOfBits); |
| | | 12 | | internal const uint TypeDef = 0x00000000; |
| | | 13 | | internal const uint MethodDef = 0x00000001; |
| | | 14 | | internal const uint TagMask = 0x0000001; |
| | | 15 | | internal const uint TagToTokenTypeByteVector = TokenTypeIds.TypeDef >> 24 | TokenTypeIds.MethodDef >> 16; |
| | | 16 | | internal const TableMask TablesReferenced = |
| | | 17 | | TableMask.TypeDef |
| | | 18 | | | TableMask.MethodDef; |
| | | 19 | | |
| | | 20 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 21 | | internal static EntityHandle ConvertToHandle(uint typeOrMethodDef) |
| | 0 | 22 | | { |
| | 0 | 23 | | uint tokenType = (TagToTokenTypeByteVector >> ((int)(typeOrMethodDef & TagMask) << 3)) << TokenTypeIds.RowId |
| | 0 | 24 | | uint rowId = (typeOrMethodDef >> NumberOfBits); |
| | | 25 | | |
| | 0 | 26 | | if ((rowId & ~TokenTypeIds.RIDMask) != 0) |
| | 0 | 27 | | { |
| | 0 | 28 | | Throw.InvalidCodedIndex(); |
| | | 29 | | } |
| | | 30 | | |
| | 0 | 31 | | return new EntityHandle(tokenType | rowId); |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | internal static uint ConvertTypeDefRowIdToTag(TypeDefinitionHandle typeDef) |
| | 0 | 35 | | { |
| | 0 | 36 | | return (uint)typeDef.RowId << NumberOfBits | TypeDef; |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | internal static uint ConvertMethodDefToTag(MethodDefinitionHandle methodDef) |
| | 0 | 40 | | { |
| | 0 | 41 | | return (uint)methodDef.RowId << NumberOfBits | MethodDef; |
| | 0 | 42 | | } |
| | | 43 | | } |
| | | 44 | | } |
| | | 45 | | |