| | | 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 HasDeclSecurityTag |
| | | 9 | | { |
| | | 10 | | internal const int NumberOfBits = 2; |
| | | 11 | | internal const int LargeRowSize = 0x00000001 << (16 - NumberOfBits); |
| | | 12 | | internal const uint TypeDef = 0x00000000; |
| | | 13 | | internal const uint MethodDef = 0x00000001; |
| | | 14 | | internal const uint Assembly = 0x00000002; |
| | | 15 | | internal const uint TagMask = 0x00000003; |
| | | 16 | | internal const TableMask TablesReferenced = |
| | | 17 | | TableMask.TypeDef |
| | | 18 | | | TableMask.MethodDef |
| | | 19 | | | TableMask.Assembly; |
| | | 20 | | internal const uint TagToTokenTypeByteVector = (TokenTypeIds.TypeDef >> 24) | (TokenTypeIds.MethodDef >> 16) | ( |
| | | 21 | | |
| | | 22 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 23 | | internal static EntityHandle ConvertToHandle(uint hasDeclSecurity) |
| | 0 | 24 | | { |
| | 0 | 25 | | uint tokenType = (TagToTokenTypeByteVector >> ((int)(hasDeclSecurity & TagMask) << 3)) << TokenTypeIds.RowId |
| | 0 | 26 | | uint rowId = (hasDeclSecurity >> NumberOfBits); |
| | | 27 | | |
| | 0 | 28 | | if (tokenType == 0 || (rowId & ~TokenTypeIds.RIDMask) != 0) |
| | 0 | 29 | | { |
| | 0 | 30 | | Throw.InvalidCodedIndex(); |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | return new EntityHandle(tokenType | rowId); |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | internal static uint ConvertToTag(EntityHandle handle) |
| | 0 | 37 | | { |
| | 0 | 38 | | uint tokenType = handle.Type; |
| | 0 | 39 | | uint rowId = (uint)handle.RowId; |
| | 0 | 40 | | return (tokenType >> TokenTypeIds.RowIdBitCount) switch |
| | 0 | 41 | | { |
| | 0 | 42 | | TokenTypeIds.TypeDef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | TypeDef, |
| | 0 | 43 | | TokenTypeIds.MethodDef >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | MethodDef, |
| | 0 | 44 | | TokenTypeIds.Assembly >> TokenTypeIds.RowIdBitCount => rowId << NumberOfBits | Assembly, |
| | 0 | 45 | | _ => 0, |
| | 0 | 46 | | }; |
| | 0 | 47 | | } |
| | | 48 | | } |
| | | 49 | | } |
| | | 50 | | |