| | | 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 HasFieldMarshalTag |
| | | 9 | | { |
| | | 10 | | internal const int NumberOfBits = 1; |
| | | 11 | | internal const int LargeRowSize = 0x00000001 << (16 - NumberOfBits); |
| | | 12 | | internal const uint Field = 0x00000000; |
| | | 13 | | internal const uint Param = 0x00000001; |
| | | 14 | | internal const uint TagMask = 0x00000001; |
| | | 15 | | internal const TableMask TablesReferenced = |
| | | 16 | | TableMask.Field |
| | | 17 | | | TableMask.Param; |
| | | 18 | | internal const uint TagToTokenTypeByteVector = TokenTypeIds.FieldDef >> 24 | TokenTypeIds.ParamDef >> 16; |
| | | 19 | | |
| | | 20 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 21 | | internal static EntityHandle ConvertToHandle(uint hasFieldMarshal) |
| | 0 | 22 | | { |
| | 0 | 23 | | uint tokenType = (TagToTokenTypeByteVector >> ((int)(hasFieldMarshal & TagMask) << 3)) << TokenTypeIds.RowId |
| | 0 | 24 | | uint rowId = (hasFieldMarshal >> 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 ConvertToTag(EntityHandle handle) |
| | 0 | 35 | | { |
| | 0 | 36 | | if (handle.Type == TokenTypeIds.FieldDef) |
| | 0 | 37 | | { |
| | 0 | 38 | | return (uint)handle.RowId << NumberOfBits | Field; |
| | | 39 | | } |
| | 0 | 40 | | else if (handle.Type == TokenTypeIds.ParamDef) |
| | 0 | 41 | | { |
| | 0 | 42 | | return (uint)handle.RowId << NumberOfBits | Param; |
| | | 43 | | } |
| | | 44 | | |
| | 0 | 45 | | return 0; |
| | 0 | 46 | | } |
| | | 47 | | } |
| | | 48 | | } |
| | | 49 | | |