| | | 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.Diagnostics; |
| | | 5 | | using System.Diagnostics.CodeAnalysis; |
| | | 6 | | using System.Reflection.Internal; |
| | | 7 | | using System.Reflection.Metadata.Ecma335; |
| | | 8 | | |
| | | 9 | | namespace System.Reflection.Metadata |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// <see cref="BlobHandle"/> representing a blob on #Blob heap in Portable PDB |
| | | 13 | | /// structured as Document Name. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <remarks> |
| | | 16 | | /// The kind of the handle is <see cref="HandleKind.Blob"/>. |
| | | 17 | | /// The handle is a specialization of <see cref="BlobHandle"/> and doesn't have a distinct kind. |
| | | 18 | | /// </remarks> |
| | | 19 | | public readonly struct DocumentNameBlobHandle : IEquatable<DocumentNameBlobHandle> |
| | | 20 | | { |
| | | 21 | | // bits: |
| | | 22 | | // 29..31: 0 |
| | | 23 | | // 0..28: #Blob heap offset |
| | | 24 | | private readonly int _heapOffset; |
| | | 25 | | |
| | | 26 | | private DocumentNameBlobHandle(int heapOffset) |
| | 0 | 27 | | { |
| | 0 | 28 | | Debug.Assert(HeapHandleType.IsValidHeapOffset((uint)heapOffset)); |
| | 0 | 29 | | _heapOffset = heapOffset; |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | internal static DocumentNameBlobHandle FromOffset(int heapOffset) |
| | 0 | 33 | | { |
| | 0 | 34 | | return new DocumentNameBlobHandle(heapOffset); |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | public static implicit operator BlobHandle(DocumentNameBlobHandle handle) |
| | 0 | 38 | | { |
| | 0 | 39 | | return BlobHandle.FromOffset(handle._heapOffset); |
| | 0 | 40 | | } |
| | | 41 | | |
| | | 42 | | public static explicit operator DocumentNameBlobHandle(BlobHandle handle) |
| | 0 | 43 | | { |
| | 0 | 44 | | if (handle.IsVirtual) |
| | 0 | 45 | | { |
| | 0 | 46 | | Throw.InvalidCast(); |
| | | 47 | | } |
| | | 48 | | |
| | 0 | 49 | | return FromOffset(handle.GetHeapOffset()); |
| | 0 | 50 | | } |
| | | 51 | | |
| | | 52 | | public bool IsNil |
| | | 53 | | { |
| | 0 | 54 | | get { return _heapOffset == 0; } |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | public override bool Equals([NotNullWhen(true)] object? obj) |
| | 0 | 58 | | { |
| | 0 | 59 | | return obj is DocumentNameBlobHandle documentHandle && Equals(documentHandle); |
| | 0 | 60 | | } |
| | | 61 | | |
| | | 62 | | public bool Equals(DocumentNameBlobHandle other) |
| | 0 | 63 | | { |
| | 0 | 64 | | return _heapOffset == other._heapOffset; |
| | 0 | 65 | | } |
| | | 66 | | |
| | | 67 | | public override int GetHashCode() |
| | 0 | 68 | | { |
| | 0 | 69 | | return _heapOffset; |
| | 0 | 70 | | } |
| | | 71 | | |
| | | 72 | | public static bool operator ==(DocumentNameBlobHandle left, DocumentNameBlobHandle right) |
| | 0 | 73 | | { |
| | 0 | 74 | | return left.Equals(right); |
| | 0 | 75 | | } |
| | | 76 | | |
| | | 77 | | public static bool operator !=(DocumentNameBlobHandle left, DocumentNameBlobHandle right) |
| | 0 | 78 | | { |
| | 0 | 79 | | return !left.Equals(right); |
| | 0 | 80 | | } |
| | | 81 | | } |
| | | 82 | | } |
| | | 83 | | |