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 // See the LICENSE file in the project root for more information. 4 5 using System.Diagnostics; 6 using System.Reflection.Metadata.Ecma335; 7 8 namespace System.Reflection.Metadata 9 { 10 public readonly struct ModuleDefinitionHandle : IEquatable<ModuleDefinitionHandle> 11 { 12 private const uint tokenType = TokenTypeIds.Module; 13 private const byte tokenTypeSmall = (byte)HandleType.Module; 14 private readonly int _rowId; 15 ModuleDefinitionHandleSystem.Reflection.Metadata.ModuleDefinitionHandle16 internal ModuleDefinitionHandle(int rowId) 17 { 18 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 19 _rowId = rowId; 20 } 21 FromRowIdSystem.Reflection.Metadata.ModuleDefinitionHandle22 internal static ModuleDefinitionHandle FromRowId(int rowId) 23 { 24 return new ModuleDefinitionHandle(rowId); 25 } 26 operator HandleSystem.Reflection.Metadata.ModuleDefinitionHandle27 public static implicit operator Handle(ModuleDefinitionHandle handle) 28 { 29 return new Handle(tokenTypeSmall, handle._rowId); 30 } 31 operator EntityHandleSystem.Reflection.Metadata.ModuleDefinitionHandle32 public static implicit operator EntityHandle(ModuleDefinitionHandle handle) 33 { 34 return new EntityHandle((uint)(tokenType | handle._rowId)); 35 } 36 operator ModuleDefinitionHandleSystem.Reflection.Metadata.ModuleDefinitionHandle37 public static explicit operator ModuleDefinitionHandle(Handle handle) 38 { 39 if (handle.VType != tokenTypeSmall) 40 { 41 Throw.InvalidCast(); 42 } 43 44 return new ModuleDefinitionHandle(handle.RowId); 45 } 46 operator ModuleDefinitionHandleSystem.Reflection.Metadata.ModuleDefinitionHandle47 public static explicit operator ModuleDefinitionHandle(EntityHandle handle) 48 { 49 if (handle.VType != tokenType) 50 { 51 Throw.InvalidCast(); 52 } 53 54 return new ModuleDefinitionHandle(handle.RowId); 55 } 56 57 public bool IsNil 58 { 59 get 60 { 61 return RowId == 0; 62 } 63 } 64 65 internal int RowId { get { return _rowId; } } 66 operator ==System.Reflection.Metadata.ModuleDefinitionHandle67 public static bool operator ==(ModuleDefinitionHandle left, ModuleDefinitionHandle right) 68 { 69 return left._rowId == right._rowId; 70 } 71 EqualsSystem.Reflection.Metadata.ModuleDefinitionHandle72 public override bool Equals(object obj) 73 { 74 return obj is ModuleDefinitionHandle && ((ModuleDefinitionHandle)obj)._rowId == _rowId; 75 } 76 EqualsSystem.Reflection.Metadata.ModuleDefinitionHandle77 public bool Equals(ModuleDefinitionHandle other) 78 { 79 return _rowId == other._rowId; 80 } 81 GetHashCodeSystem.Reflection.Metadata.ModuleDefinitionHandle82 public override int GetHashCode() 83 { 84 return _rowId.GetHashCode(); 85 } 86 operator !=System.Reflection.Metadata.ModuleDefinitionHandle87 public static bool operator !=(ModuleDefinitionHandle left, ModuleDefinitionHandle right) 88 { 89 return left._rowId != right._rowId; 90 } 91 } 92 93 public readonly struct AssemblyDefinitionHandle : IEquatable<AssemblyDefinitionHandle> 94 { 95 private const uint tokenType = TokenTypeIds.Assembly; 96 private const byte tokenTypeSmall = (byte)HandleType.Assembly; 97 private readonly int _rowId; 98 AssemblyDefinitionHandleSystem.Reflection.Metadata.AssemblyDefinitionHandle99 internal AssemblyDefinitionHandle(int rowId) 100 { 101 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 102 _rowId = rowId; 103 } 104 FromRowIdSystem.Reflection.Metadata.AssemblyDefinitionHandle105 internal static AssemblyDefinitionHandle FromRowId(int rowId) 106 { 107 return new AssemblyDefinitionHandle(rowId); 108 } 109 operator HandleSystem.Reflection.Metadata.AssemblyDefinitionHandle110 public static implicit operator Handle(AssemblyDefinitionHandle handle) 111 { 112 return new Handle(tokenTypeSmall, handle._rowId); 113 } 114 operator EntityHandleSystem.Reflection.Metadata.AssemblyDefinitionHandle115 public static implicit operator EntityHandle(AssemblyDefinitionHandle handle) 116 { 117 return new EntityHandle((uint)(tokenType | handle._rowId)); 118 } 119 operator AssemblyDefinitionHandleSystem.Reflection.Metadata.AssemblyDefinitionHandle120 public static explicit operator AssemblyDefinitionHandle(Handle handle) 121 { 122 if (handle.VType != tokenTypeSmall) 123 { 124 Throw.InvalidCast(); 125 } 126 127 return new AssemblyDefinitionHandle(handle.RowId); 128 } 129 operator AssemblyDefinitionHandleSystem.Reflection.Metadata.AssemblyDefinitionHandle130 public static explicit operator AssemblyDefinitionHandle(EntityHandle handle) 131 { 132 if (handle.VType != tokenType) 133 { 134 Throw.InvalidCast(); 135 } 136 137 return new AssemblyDefinitionHandle(handle.RowId); 138 } 139 140 public bool IsNil 141 { 142 get 143 { 144 return RowId == 0; 145 } 146 } 147 148 internal int RowId { get { return _rowId; } } 149 operator ==System.Reflection.Metadata.AssemblyDefinitionHandle150 public static bool operator ==(AssemblyDefinitionHandle left, AssemblyDefinitionHandle right) 151 { 152 return left._rowId == right._rowId; 153 } 154 EqualsSystem.Reflection.Metadata.AssemblyDefinitionHandle155 public override bool Equals(object obj) 156 { 157 return obj is AssemblyDefinitionHandle && ((AssemblyDefinitionHandle)obj)._rowId == _rowId; 158 } 159 EqualsSystem.Reflection.Metadata.AssemblyDefinitionHandle160 public bool Equals(AssemblyDefinitionHandle other) 161 { 162 return _rowId == other._rowId; 163 } 164 GetHashCodeSystem.Reflection.Metadata.AssemblyDefinitionHandle165 public override int GetHashCode() 166 { 167 return _rowId.GetHashCode(); 168 } 169 operator !=System.Reflection.Metadata.AssemblyDefinitionHandle170 public static bool operator !=(AssemblyDefinitionHandle left, AssemblyDefinitionHandle right) 171 { 172 return left._rowId != right._rowId; 173 } 174 } 175 176 public readonly struct InterfaceImplementationHandle : IEquatable<InterfaceImplementationHandle> 177 { 178 private const uint tokenType = TokenTypeIds.InterfaceImpl; 179 private const byte tokenTypeSmall = (byte)HandleType.InterfaceImpl; 180 private readonly int _rowId; 181 InterfaceImplementationHandleSystem.Reflection.Metadata.InterfaceImplementationHandle182 internal InterfaceImplementationHandle(int rowId) 183 { 184 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 185 _rowId = rowId; 186 } 187 FromRowIdSystem.Reflection.Metadata.InterfaceImplementationHandle188 internal static InterfaceImplementationHandle FromRowId(int rowId) 189 { 190 return new InterfaceImplementationHandle(rowId); 191 } 192 operator HandleSystem.Reflection.Metadata.InterfaceImplementationHandle193 public static implicit operator Handle(InterfaceImplementationHandle handle) 194 { 195 return new Handle(tokenTypeSmall, handle._rowId); 196 } 197 operator EntityHandleSystem.Reflection.Metadata.InterfaceImplementationHandle198 public static implicit operator EntityHandle(InterfaceImplementationHandle handle) 199 { 200 return new EntityHandle((uint)(tokenType | handle._rowId)); 201 } 202 operator InterfaceImplementationHandleSystem.Reflection.Metadata.InterfaceImplementationHandle203 public static explicit operator InterfaceImplementationHandle(Handle handle) 204 { 205 if (handle.VType != tokenTypeSmall) 206 { 207 Throw.InvalidCast(); 208 } 209 210 return new InterfaceImplementationHandle(handle.RowId); 211 } 212 operator InterfaceImplementationHandleSystem.Reflection.Metadata.InterfaceImplementationHandle213 public static explicit operator InterfaceImplementationHandle(EntityHandle handle) 214 { 215 if (handle.VType != tokenType) 216 { 217 Throw.InvalidCast(); 218 } 219 220 return new InterfaceImplementationHandle(handle.RowId); 221 } 222 223 public bool IsNil 224 { 225 get 226 { 227 return RowId == 0; 228 } 229 } 230 231 internal int RowId { get { return _rowId; } } 232 operator ==System.Reflection.Metadata.InterfaceImplementationHandle233 public static bool operator ==(InterfaceImplementationHandle left, InterfaceImplementationHandle right) 234 { 235 return left._rowId == right._rowId; 236 } 237 EqualsSystem.Reflection.Metadata.InterfaceImplementationHandle238 public override bool Equals(object obj) 239 { 240 return obj is InterfaceImplementationHandle && ((InterfaceImplementationHandle)obj)._rowId == _rowId; 241 } 242 EqualsSystem.Reflection.Metadata.InterfaceImplementationHandle243 public bool Equals(InterfaceImplementationHandle other) 244 { 245 return _rowId == other._rowId; 246 } 247 GetHashCodeSystem.Reflection.Metadata.InterfaceImplementationHandle248 public override int GetHashCode() 249 { 250 return _rowId.GetHashCode(); 251 } 252 operator !=System.Reflection.Metadata.InterfaceImplementationHandle253 public static bool operator !=(InterfaceImplementationHandle left, InterfaceImplementationHandle right) 254 { 255 return left._rowId != right._rowId; 256 } 257 } 258 259 public readonly struct MethodDefinitionHandle : IEquatable<MethodDefinitionHandle> 260 { 261 private const uint tokenType = TokenTypeIds.MethodDef; 262 private const byte tokenTypeSmall = (byte)HandleType.MethodDef; 263 private readonly int _rowId; 264 MethodDefinitionHandleSystem.Reflection.Metadata.MethodDefinitionHandle265 private MethodDefinitionHandle(int rowId) 266 { 267 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 268 _rowId = rowId; 269 } 270 FromRowIdSystem.Reflection.Metadata.MethodDefinitionHandle271 internal static MethodDefinitionHandle FromRowId(int rowId) 272 { 273 return new MethodDefinitionHandle(rowId); 274 } 275 operator HandleSystem.Reflection.Metadata.MethodDefinitionHandle276 public static implicit operator Handle(MethodDefinitionHandle handle) 277 { 278 return new Handle(tokenTypeSmall, handle._rowId); 279 } 280 operator EntityHandleSystem.Reflection.Metadata.MethodDefinitionHandle281 public static implicit operator EntityHandle(MethodDefinitionHandle handle) 282 { 283 return new EntityHandle((uint)(tokenType | handle._rowId)); 284 } 285 operator MethodDefinitionHandleSystem.Reflection.Metadata.MethodDefinitionHandle286 public static explicit operator MethodDefinitionHandle(Handle handle) 287 { 288 if (handle.VType != tokenTypeSmall) 289 { 290 Throw.InvalidCast(); 291 } 292 293 return new MethodDefinitionHandle(handle.RowId); 294 } 295 operator MethodDefinitionHandleSystem.Reflection.Metadata.MethodDefinitionHandle296 public static explicit operator MethodDefinitionHandle(EntityHandle handle) 297 { 298 if (handle.VType != tokenType) 299 { 300 Throw.InvalidCast(); 301 } 302 303 return new MethodDefinitionHandle(handle.RowId); 304 } 305 306 public bool IsNil 307 { 308 get 309 { 310 return RowId == 0; 311 } 312 } 313 314 internal int RowId { get { return _rowId; } } 315 operator ==System.Reflection.Metadata.MethodDefinitionHandle316 public static bool operator ==(MethodDefinitionHandle left, MethodDefinitionHandle right) 317 { 318 return left._rowId == right._rowId; 319 } 320 EqualsSystem.Reflection.Metadata.MethodDefinitionHandle321 public override bool Equals(object obj) 322 { 323 return obj is MethodDefinitionHandle && ((MethodDefinitionHandle)obj)._rowId == _rowId; 324 } 325 EqualsSystem.Reflection.Metadata.MethodDefinitionHandle326 public bool Equals(MethodDefinitionHandle other) 327 { 328 return _rowId == other._rowId; 329 } 330 GetHashCodeSystem.Reflection.Metadata.MethodDefinitionHandle331 public override int GetHashCode() 332 { 333 return _rowId.GetHashCode(); 334 } 335 operator !=System.Reflection.Metadata.MethodDefinitionHandle336 public static bool operator !=(MethodDefinitionHandle left, MethodDefinitionHandle right) 337 { 338 return left._rowId != right._rowId; 339 } 340 341 /// <summary> 342 /// Returns a handle to <see cref="MethodDebugInformation"/> corresponding to this handle. 343 /// </summary> 344 /// <remarks> 345 /// The resulting handle is only valid within the context of a <see cref="MetadataReader"/> open on the Portable PDB blob, 346 /// which in case of standalone PDB file is a different reader than the one containing this method definition. 347 /// </remarks> ToDebugInformationHandleSystem.Reflection.Metadata.MethodDefinitionHandle348 public MethodDebugInformationHandle ToDebugInformationHandle() 349 { 350 return MethodDebugInformationHandle.FromRowId(_rowId); 351 } 352 } 353 354 public readonly struct MethodImplementationHandle : IEquatable<MethodImplementationHandle> 355 { 356 private const uint tokenType = TokenTypeIds.MethodImpl; 357 private const byte tokenTypeSmall = (byte)HandleType.MethodImpl; 358 private readonly int _rowId; 359 MethodImplementationHandleSystem.Reflection.Metadata.MethodImplementationHandle360 private MethodImplementationHandle(int rowId) 361 { 362 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 363 _rowId = rowId; 364 } 365 FromRowIdSystem.Reflection.Metadata.MethodImplementationHandle366 internal static MethodImplementationHandle FromRowId(int rowId) 367 { 368 return new MethodImplementationHandle(rowId); 369 } 370 operator HandleSystem.Reflection.Metadata.MethodImplementationHandle371 public static implicit operator Handle(MethodImplementationHandle handle) 372 { 373 return new Handle(tokenTypeSmall, handle._rowId); 374 } 375 operator EntityHandleSystem.Reflection.Metadata.MethodImplementationHandle376 public static implicit operator EntityHandle(MethodImplementationHandle handle) 377 { 378 return new EntityHandle((uint)(tokenType | handle._rowId)); 379 } 380 operator MethodImplementationHandleSystem.Reflection.Metadata.MethodImplementationHandle381 public static explicit operator MethodImplementationHandle(Handle handle) 382 { 383 if (handle.VType != tokenTypeSmall) 384 { 385 Throw.InvalidCast(); 386 } 387 388 return new MethodImplementationHandle(handle.RowId); 389 } 390 operator MethodImplementationHandleSystem.Reflection.Metadata.MethodImplementationHandle391 public static explicit operator MethodImplementationHandle(EntityHandle handle) 392 { 393 if (handle.VType != tokenType) 394 { 395 Throw.InvalidCast(); 396 } 397 398 return new MethodImplementationHandle(handle.RowId); 399 } 400 401 public bool IsNil 402 { 403 get 404 { 405 return RowId == 0; 406 } 407 } 408 409 internal int RowId { get { return _rowId; } } 410 operator ==System.Reflection.Metadata.MethodImplementationHandle411 public static bool operator ==(MethodImplementationHandle left, MethodImplementationHandle right) 412 { 413 return left._rowId == right._rowId; 414 } 415 EqualsSystem.Reflection.Metadata.MethodImplementationHandle416 public override bool Equals(object obj) 417 { 418 return obj is MethodImplementationHandle && ((MethodImplementationHandle)obj)._rowId == _rowId; 419 } 420 EqualsSystem.Reflection.Metadata.MethodImplementationHandle421 public bool Equals(MethodImplementationHandle other) 422 { 423 return _rowId == other._rowId; 424 } 425 GetHashCodeSystem.Reflection.Metadata.MethodImplementationHandle426 public override int GetHashCode() 427 { 428 return _rowId.GetHashCode(); 429 } 430 operator !=System.Reflection.Metadata.MethodImplementationHandle431 public static bool operator !=(MethodImplementationHandle left, MethodImplementationHandle right) 432 { 433 return left._rowId != right._rowId; 434 } 435 } 436 437 public readonly struct MethodSpecificationHandle : IEquatable<MethodSpecificationHandle> 438 { 439 private const uint tokenType = TokenTypeIds.MethodSpec; 440 private const byte tokenTypeSmall = (byte)HandleType.MethodSpec; 441 private readonly int _rowId; 442 MethodSpecificationHandleSystem.Reflection.Metadata.MethodSpecificationHandle443 private MethodSpecificationHandle(int rowId) 444 { 445 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 446 _rowId = rowId; 447 } 448 FromRowIdSystem.Reflection.Metadata.MethodSpecificationHandle449 internal static MethodSpecificationHandle FromRowId(int rowId) 450 { 451 return new MethodSpecificationHandle(rowId); 452 } 453 operator HandleSystem.Reflection.Metadata.MethodSpecificationHandle454 public static implicit operator Handle(MethodSpecificationHandle handle) 455 { 456 return new Handle(tokenTypeSmall, handle._rowId); 457 } 458 operator EntityHandleSystem.Reflection.Metadata.MethodSpecificationHandle459 public static implicit operator EntityHandle(MethodSpecificationHandle handle) 460 { 461 return new EntityHandle((uint)(tokenType | handle._rowId)); 462 } 463 operator MethodSpecificationHandleSystem.Reflection.Metadata.MethodSpecificationHandle464 public static explicit operator MethodSpecificationHandle(Handle handle) 465 { 466 if (handle.VType != tokenTypeSmall) 467 { 468 Throw.InvalidCast(); 469 } 470 471 return new MethodSpecificationHandle(handle.RowId); 472 } 473 operator MethodSpecificationHandleSystem.Reflection.Metadata.MethodSpecificationHandle474 public static explicit operator MethodSpecificationHandle(EntityHandle handle) 475 { 476 if (handle.VType != tokenType) 477 { 478 Throw.InvalidCast(); 479 } 480 481 return new MethodSpecificationHandle(handle.RowId); 482 } 483 484 public bool IsNil 485 { 486 get 487 { 488 return RowId == 0; 489 } 490 } 491 492 internal int RowId { get { return _rowId; } } 493 operator ==System.Reflection.Metadata.MethodSpecificationHandle494 public static bool operator ==(MethodSpecificationHandle left, MethodSpecificationHandle right) 495 { 496 return left._rowId == right._rowId; 497 } 498 EqualsSystem.Reflection.Metadata.MethodSpecificationHandle499 public override bool Equals(object obj) 500 { 501 return obj is MethodSpecificationHandle && ((MethodSpecificationHandle)obj)._rowId == _rowId; 502 } 503 EqualsSystem.Reflection.Metadata.MethodSpecificationHandle504 public bool Equals(MethodSpecificationHandle other) 505 { 506 return _rowId == other._rowId; 507 } 508 GetHashCodeSystem.Reflection.Metadata.MethodSpecificationHandle509 public override int GetHashCode() 510 { 511 return _rowId.GetHashCode(); 512 } 513 operator !=System.Reflection.Metadata.MethodSpecificationHandle514 public static bool operator !=(MethodSpecificationHandle left, MethodSpecificationHandle right) 515 { 516 return left._rowId != right._rowId; 517 } 518 } 519 520 public readonly struct TypeDefinitionHandle : IEquatable<TypeDefinitionHandle> 521 { 522 private const uint tokenType = TokenTypeIds.TypeDef; 523 private const byte tokenTypeSmall = (byte)HandleType.TypeDef; 524 private readonly int _rowId; 525 TypeDefinitionHandleSystem.Reflection.Metadata.TypeDefinitionHandle526 private TypeDefinitionHandle(int rowId) 527 { 528 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 529 _rowId = rowId; 530 } 531 FromRowIdSystem.Reflection.Metadata.TypeDefinitionHandle532 internal static TypeDefinitionHandle FromRowId(int rowId) 533 { 534 return new TypeDefinitionHandle(rowId); 535 } 536 operator HandleSystem.Reflection.Metadata.TypeDefinitionHandle537 public static implicit operator Handle(TypeDefinitionHandle handle) 538 { 539 return new Handle(tokenTypeSmall, handle._rowId); 540 } 541 operator EntityHandleSystem.Reflection.Metadata.TypeDefinitionHandle542 public static implicit operator EntityHandle(TypeDefinitionHandle handle) 543 { 544 return new EntityHandle((uint)(tokenType | handle._rowId)); 545 } 546 operator TypeDefinitionHandleSystem.Reflection.Metadata.TypeDefinitionHandle547 public static explicit operator TypeDefinitionHandle(Handle handle) 548 { 549 if (handle.VType != tokenTypeSmall) 550 { 551 Throw.InvalidCast(); 552 } 553 554 return new TypeDefinitionHandle(handle.RowId); 555 } 556 operator TypeDefinitionHandleSystem.Reflection.Metadata.TypeDefinitionHandle557 public static explicit operator TypeDefinitionHandle(EntityHandle handle) 558 { 559 if (handle.VType != tokenType) 560 { 561 Throw.InvalidCast(); 562 } 563 564 return new TypeDefinitionHandle(handle.RowId); 565 } 566 567 public bool IsNil 568 { 569 get 570 { 571 return RowId == 0; 572 } 573 } 574 575 internal int RowId { get { return _rowId; } } 576 operator ==System.Reflection.Metadata.TypeDefinitionHandle577 public static bool operator ==(TypeDefinitionHandle left, TypeDefinitionHandle right) 578 { 579 return left._rowId == right._rowId; 580 } 581 EqualsSystem.Reflection.Metadata.TypeDefinitionHandle582 public override bool Equals(object obj) 583 { 584 return obj is TypeDefinitionHandle && ((TypeDefinitionHandle)obj)._rowId == _rowId; 585 } 586 EqualsSystem.Reflection.Metadata.TypeDefinitionHandle587 public bool Equals(TypeDefinitionHandle other) 588 { 589 return _rowId == other._rowId; 590 } 591 GetHashCodeSystem.Reflection.Metadata.TypeDefinitionHandle592 public override int GetHashCode() 593 { 594 return _rowId.GetHashCode(); 595 } 596 operator !=System.Reflection.Metadata.TypeDefinitionHandle597 public static bool operator !=(TypeDefinitionHandle left, TypeDefinitionHandle right) 598 { 599 return left._rowId != right._rowId; 600 } 601 } 602 603 public readonly struct ExportedTypeHandle : IEquatable<ExportedTypeHandle> 604 { 605 private const uint tokenType = TokenTypeIds.ExportedType; 606 private const byte tokenTypeSmall = (byte)HandleType.ExportedType; 607 private readonly int _rowId; 608 ExportedTypeHandleSystem.Reflection.Metadata.ExportedTypeHandle609 private ExportedTypeHandle(int rowId) 610 { 611 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 612 _rowId = rowId; 613 } 614 FromRowIdSystem.Reflection.Metadata.ExportedTypeHandle615 internal static ExportedTypeHandle FromRowId(int rowId) 616 { 617 return new ExportedTypeHandle(rowId); 618 } 619 operator HandleSystem.Reflection.Metadata.ExportedTypeHandle620 public static implicit operator Handle(ExportedTypeHandle handle) 621 { 622 return new Handle(tokenTypeSmall, handle._rowId); 623 } 624 operator EntityHandleSystem.Reflection.Metadata.ExportedTypeHandle625 public static implicit operator EntityHandle(ExportedTypeHandle handle) 626 { 627 return new EntityHandle((uint)(tokenType | handle._rowId)); 628 } 629 operator ExportedTypeHandleSystem.Reflection.Metadata.ExportedTypeHandle630 public static explicit operator ExportedTypeHandle(Handle handle) 631 { 632 if (handle.VType != tokenTypeSmall) 633 { 634 Throw.InvalidCast(); 635 } 636 637 return new ExportedTypeHandle(handle.RowId); 638 } 639 operator ExportedTypeHandleSystem.Reflection.Metadata.ExportedTypeHandle640 public static explicit operator ExportedTypeHandle(EntityHandle handle) 641 { 642 if (handle.VType != tokenType) 643 { 644 Throw.InvalidCast(); 645 } 646 647 return new ExportedTypeHandle(handle.RowId); 648 } 649 650 public bool IsNil 651 { 652 get 653 { 654 return RowId == 0; 655 } 656 } 657 658 internal int RowId { get { return _rowId; } } 659 operator ==System.Reflection.Metadata.ExportedTypeHandle660 public static bool operator ==(ExportedTypeHandle left, ExportedTypeHandle right) 661 { 662 return left._rowId == right._rowId; 663 } 664 EqualsSystem.Reflection.Metadata.ExportedTypeHandle665 public override bool Equals(object obj) 666 { 667 return obj is ExportedTypeHandle && ((ExportedTypeHandle)obj)._rowId == _rowId; 668 } 669 EqualsSystem.Reflection.Metadata.ExportedTypeHandle670 public bool Equals(ExportedTypeHandle other) 671 { 672 return _rowId == other._rowId; 673 } 674 GetHashCodeSystem.Reflection.Metadata.ExportedTypeHandle675 public override int GetHashCode() 676 { 677 return _rowId.GetHashCode(); 678 } 679 operator !=System.Reflection.Metadata.ExportedTypeHandle680 public static bool operator !=(ExportedTypeHandle left, ExportedTypeHandle right) 681 { 682 return left._rowId != right._rowId; 683 } 684 } 685 686 public readonly struct TypeReferenceHandle : IEquatable<TypeReferenceHandle> 687 { 688 private const uint tokenType = TokenTypeIds.TypeRef; 689 private const byte tokenTypeSmall = (byte)HandleType.TypeRef; 690 private readonly int _rowId; 691 TypeReferenceHandleSystem.Reflection.Metadata.TypeReferenceHandle692 private TypeReferenceHandle(int rowId) 693 { 694 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 695 _rowId = rowId; 696 } 697 FromRowIdSystem.Reflection.Metadata.TypeReferenceHandle698 internal static TypeReferenceHandle FromRowId(int rowId) 699 { 700 return new TypeReferenceHandle(rowId); 701 } 702 operator HandleSystem.Reflection.Metadata.TypeReferenceHandle703 public static implicit operator Handle(TypeReferenceHandle handle) 704 { 705 return new Handle(tokenTypeSmall, handle._rowId); 706 } 707 operator EntityHandleSystem.Reflection.Metadata.TypeReferenceHandle708 public static implicit operator EntityHandle(TypeReferenceHandle handle) 709 { 710 return new EntityHandle((uint)(tokenType | handle._rowId)); 711 } 712 operator TypeReferenceHandleSystem.Reflection.Metadata.TypeReferenceHandle713 public static explicit operator TypeReferenceHandle(Handle handle) 714 { 715 if (handle.VType != tokenTypeSmall) 716 { 717 Throw.InvalidCast(); 718 } 719 720 return new TypeReferenceHandle(handle.RowId); 721 } 722 operator TypeReferenceHandleSystem.Reflection.Metadata.TypeReferenceHandle723 public static explicit operator TypeReferenceHandle(EntityHandle handle) 724 { 725 if (handle.VType != tokenType) 726 { 727 Throw.InvalidCast(); 728 } 729 730 return new TypeReferenceHandle(handle.RowId); 731 } 732 733 public bool IsNil 734 { 735 get 736 { 737 return RowId == 0; 738 } 739 } 740 741 internal int RowId { get { return _rowId; } } 742 operator ==System.Reflection.Metadata.TypeReferenceHandle743 public static bool operator ==(TypeReferenceHandle left, TypeReferenceHandle right) 744 { 745 return left._rowId == right._rowId; 746 } 747 EqualsSystem.Reflection.Metadata.TypeReferenceHandle748 public override bool Equals(object obj) 749 { 750 return obj is TypeReferenceHandle && ((TypeReferenceHandle)obj)._rowId == _rowId; 751 } 752 EqualsSystem.Reflection.Metadata.TypeReferenceHandle753 public bool Equals(TypeReferenceHandle other) 754 { 755 return _rowId == other._rowId; 756 } 757 GetHashCodeSystem.Reflection.Metadata.TypeReferenceHandle758 public override int GetHashCode() 759 { 760 return _rowId.GetHashCode(); 761 } 762 operator !=System.Reflection.Metadata.TypeReferenceHandle763 public static bool operator !=(TypeReferenceHandle left, TypeReferenceHandle right) 764 { 765 return left._rowId != right._rowId; 766 } 767 } 768 769 public readonly struct TypeSpecificationHandle : IEquatable<TypeSpecificationHandle> 770 { 771 private const uint tokenType = TokenTypeIds.TypeSpec; 772 private const byte tokenTypeSmall = (byte)HandleType.TypeSpec; 773 private readonly int _rowId; 774 TypeSpecificationHandleSystem.Reflection.Metadata.TypeSpecificationHandle775 private TypeSpecificationHandle(int rowId) 776 { 777 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 778 _rowId = rowId; 779 } 780 FromRowIdSystem.Reflection.Metadata.TypeSpecificationHandle781 internal static TypeSpecificationHandle FromRowId(int rowId) 782 { 783 return new TypeSpecificationHandle(rowId); 784 } 785 operator HandleSystem.Reflection.Metadata.TypeSpecificationHandle786 public static implicit operator Handle(TypeSpecificationHandle handle) 787 { 788 return new Handle(tokenTypeSmall, handle._rowId); 789 } 790 operator EntityHandleSystem.Reflection.Metadata.TypeSpecificationHandle791 public static implicit operator EntityHandle(TypeSpecificationHandle handle) 792 { 793 return new EntityHandle((uint)(tokenType | handle._rowId)); 794 } 795 operator TypeSpecificationHandleSystem.Reflection.Metadata.TypeSpecificationHandle796 public static explicit operator TypeSpecificationHandle(Handle handle) 797 { 798 if (handle.VType != tokenTypeSmall) 799 { 800 Throw.InvalidCast(); 801 } 802 803 return new TypeSpecificationHandle(handle.RowId); 804 } 805 operator TypeSpecificationHandleSystem.Reflection.Metadata.TypeSpecificationHandle806 public static explicit operator TypeSpecificationHandle(EntityHandle handle) 807 { 808 if (handle.VType != tokenType) 809 { 810 Throw.InvalidCast(); 811 } 812 813 return new TypeSpecificationHandle(handle.RowId); 814 } 815 816 public bool IsNil 817 { 818 get 819 { 820 return RowId == 0; 821 } 822 } 823 824 internal int RowId { get { return _rowId; } } 825 operator ==System.Reflection.Metadata.TypeSpecificationHandle826 public static bool operator ==(TypeSpecificationHandle left, TypeSpecificationHandle right) 827 { 828 return left._rowId == right._rowId; 829 } 830 EqualsSystem.Reflection.Metadata.TypeSpecificationHandle831 public override bool Equals(object obj) 832 { 833 return obj is TypeSpecificationHandle && ((TypeSpecificationHandle)obj)._rowId == _rowId; 834 } 835 EqualsSystem.Reflection.Metadata.TypeSpecificationHandle836 public bool Equals(TypeSpecificationHandle other) 837 { 838 return _rowId == other._rowId; 839 } 840 GetHashCodeSystem.Reflection.Metadata.TypeSpecificationHandle841 public override int GetHashCode() 842 { 843 return _rowId.GetHashCode(); 844 } 845 operator !=System.Reflection.Metadata.TypeSpecificationHandle846 public static bool operator !=(TypeSpecificationHandle left, TypeSpecificationHandle right) 847 { 848 return left._rowId != right._rowId; 849 } 850 } 851 852 public readonly struct MemberReferenceHandle : IEquatable<MemberReferenceHandle> 853 { 854 private const uint tokenType = TokenTypeIds.MemberRef; 855 private const byte tokenTypeSmall = (byte)HandleType.MemberRef; 856 private readonly int _rowId; 857 MemberReferenceHandleSystem.Reflection.Metadata.MemberReferenceHandle858 private MemberReferenceHandle(int rowId) 859 { 860 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 861 _rowId = rowId; 862 } 863 FromRowIdSystem.Reflection.Metadata.MemberReferenceHandle864 internal static MemberReferenceHandle FromRowId(int rowId) 865 { 866 return new MemberReferenceHandle(rowId); 867 } 868 operator HandleSystem.Reflection.Metadata.MemberReferenceHandle869 public static implicit operator Handle(MemberReferenceHandle handle) 870 { 871 return new Handle(tokenTypeSmall, handle._rowId); 872 } 873 operator EntityHandleSystem.Reflection.Metadata.MemberReferenceHandle874 public static implicit operator EntityHandle(MemberReferenceHandle handle) 875 { 876 return new EntityHandle((uint)(tokenType | handle._rowId)); 877 } 878 operator MemberReferenceHandleSystem.Reflection.Metadata.MemberReferenceHandle879 public static explicit operator MemberReferenceHandle(Handle handle) 880 { 881 if (handle.VType != tokenTypeSmall) 882 { 883 Throw.InvalidCast(); 884 } 885 886 return new MemberReferenceHandle(handle.RowId); 887 } 888 operator MemberReferenceHandleSystem.Reflection.Metadata.MemberReferenceHandle889 public static explicit operator MemberReferenceHandle(EntityHandle handle) 890 { 891 if (handle.VType != tokenType) 892 { 893 Throw.InvalidCast(); 894 } 895 896 return new MemberReferenceHandle(handle.RowId); 897 } 898 899 public bool IsNil 900 { 901 get 902 { 903 return RowId == 0; 904 } 905 } 906 907 internal int RowId { get { return _rowId; } } 908 operator ==System.Reflection.Metadata.MemberReferenceHandle909 public static bool operator ==(MemberReferenceHandle left, MemberReferenceHandle right) 910 { 911 return left._rowId == right._rowId; 912 } 913 EqualsSystem.Reflection.Metadata.MemberReferenceHandle914 public override bool Equals(object obj) 915 { 916 return obj is MemberReferenceHandle && ((MemberReferenceHandle)obj)._rowId == _rowId; 917 } 918 EqualsSystem.Reflection.Metadata.MemberReferenceHandle919 public bool Equals(MemberReferenceHandle other) 920 { 921 return _rowId == other._rowId; 922 } 923 GetHashCodeSystem.Reflection.Metadata.MemberReferenceHandle924 public override int GetHashCode() 925 { 926 return _rowId.GetHashCode(); 927 } 928 operator !=System.Reflection.Metadata.MemberReferenceHandle929 public static bool operator !=(MemberReferenceHandle left, MemberReferenceHandle right) 930 { 931 return left._rowId != right._rowId; 932 } 933 } 934 935 public readonly struct FieldDefinitionHandle : IEquatable<FieldDefinitionHandle> 936 { 937 private const uint tokenType = TokenTypeIds.FieldDef; 938 private const byte tokenTypeSmall = (byte)HandleType.FieldDef; 939 private readonly int _rowId; 940 FieldDefinitionHandleSystem.Reflection.Metadata.FieldDefinitionHandle941 private FieldDefinitionHandle(int rowId) 942 { 943 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 944 _rowId = rowId; 945 } 946 FromRowIdSystem.Reflection.Metadata.FieldDefinitionHandle947 internal static FieldDefinitionHandle FromRowId(int rowId) 948 { 949 return new FieldDefinitionHandle(rowId); 950 } 951 operator HandleSystem.Reflection.Metadata.FieldDefinitionHandle952 public static implicit operator Handle(FieldDefinitionHandle handle) 953 { 954 return new Handle(tokenTypeSmall, handle._rowId); 955 } 956 operator EntityHandleSystem.Reflection.Metadata.FieldDefinitionHandle957 public static implicit operator EntityHandle(FieldDefinitionHandle handle) 958 { 959 return new EntityHandle((uint)(tokenType | handle._rowId)); 960 } 961 operator FieldDefinitionHandleSystem.Reflection.Metadata.FieldDefinitionHandle962 public static explicit operator FieldDefinitionHandle(Handle handle) 963 { 964 if (handle.VType != tokenTypeSmall) 965 { 966 Throw.InvalidCast(); 967 } 968 969 return new FieldDefinitionHandle(handle.RowId); 970 } 971 operator FieldDefinitionHandleSystem.Reflection.Metadata.FieldDefinitionHandle972 public static explicit operator FieldDefinitionHandle(EntityHandle handle) 973 { 974 if (handle.VType != tokenType) 975 { 976 Throw.InvalidCast(); 977 } 978 979 return new FieldDefinitionHandle(handle.RowId); 980 } 981 982 public bool IsNil 983 { 984 get 985 { 986 return RowId == 0; 987 } 988 } 989 990 internal int RowId { get { return _rowId; } } 991 operator ==System.Reflection.Metadata.FieldDefinitionHandle992 public static bool operator ==(FieldDefinitionHandle left, FieldDefinitionHandle right) 993 { 994 return left._rowId == right._rowId; 995 } 996 EqualsSystem.Reflection.Metadata.FieldDefinitionHandle997 public override bool Equals(object obj) 998 { 999 return obj is FieldDefinitionHandle && ((FieldDefinitionHandle)obj)._rowId == _rowId; 1000 } 1001 EqualsSystem.Reflection.Metadata.FieldDefinitionHandle1002 public bool Equals(FieldDefinitionHandle other) 1003 { 1004 return _rowId == other._rowId; 1005 } 1006 GetHashCodeSystem.Reflection.Metadata.FieldDefinitionHandle1007 public override int GetHashCode() 1008 { 1009 return _rowId.GetHashCode(); 1010 } 1011 operator !=System.Reflection.Metadata.FieldDefinitionHandle1012 public static bool operator !=(FieldDefinitionHandle left, FieldDefinitionHandle right) 1013 { 1014 return left._rowId != right._rowId; 1015 } 1016 } 1017 1018 public readonly struct EventDefinitionHandle : IEquatable<EventDefinitionHandle> 1019 { 1020 private const uint tokenType = TokenTypeIds.Event; 1021 private const byte tokenTypeSmall = (byte)HandleType.Event; 1022 private readonly int _rowId; 1023 EventDefinitionHandleSystem.Reflection.Metadata.EventDefinitionHandle1024 private EventDefinitionHandle(int rowId) 1025 { 1026 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1027 _rowId = rowId; 1028 } 1029 FromRowIdSystem.Reflection.Metadata.EventDefinitionHandle1030 internal static EventDefinitionHandle FromRowId(int rowId) 1031 { 1032 return new EventDefinitionHandle(rowId); 1033 } 1034 operator HandleSystem.Reflection.Metadata.EventDefinitionHandle1035 public static implicit operator Handle(EventDefinitionHandle handle) 1036 { 1037 return new Handle(tokenTypeSmall, handle._rowId); 1038 } 1039 operator EntityHandleSystem.Reflection.Metadata.EventDefinitionHandle1040 public static implicit operator EntityHandle(EventDefinitionHandle handle) 1041 { 1042 return new EntityHandle((uint)(tokenType | handle._rowId)); 1043 } 1044 operator EventDefinitionHandleSystem.Reflection.Metadata.EventDefinitionHandle1045 public static explicit operator EventDefinitionHandle(Handle handle) 1046 { 1047 if (handle.VType != tokenTypeSmall) 1048 { 1049 Throw.InvalidCast(); 1050 } 1051 1052 return new EventDefinitionHandle(handle.RowId); 1053 } 1054 operator EventDefinitionHandleSystem.Reflection.Metadata.EventDefinitionHandle1055 public static explicit operator EventDefinitionHandle(EntityHandle handle) 1056 { 1057 if (handle.VType != tokenType) 1058 { 1059 Throw.InvalidCast(); 1060 } 1061 1062 return new EventDefinitionHandle(handle.RowId); 1063 } 1064 1065 public bool IsNil 1066 { 1067 get 1068 { 1069 return RowId == 0; 1070 } 1071 } 1072 1073 internal int RowId { get { return _rowId; } } 1074 operator ==System.Reflection.Metadata.EventDefinitionHandle1075 public static bool operator ==(EventDefinitionHandle left, EventDefinitionHandle right) 1076 { 1077 return left._rowId == right._rowId; 1078 } 1079 EqualsSystem.Reflection.Metadata.EventDefinitionHandle1080 public override bool Equals(object obj) 1081 { 1082 return obj is EventDefinitionHandle && ((EventDefinitionHandle)obj)._rowId == _rowId; 1083 } 1084 EqualsSystem.Reflection.Metadata.EventDefinitionHandle1085 public bool Equals(EventDefinitionHandle other) 1086 { 1087 return _rowId == other._rowId; 1088 } 1089 GetHashCodeSystem.Reflection.Metadata.EventDefinitionHandle1090 public override int GetHashCode() 1091 { 1092 return _rowId.GetHashCode(); 1093 } 1094 operator !=System.Reflection.Metadata.EventDefinitionHandle1095 public static bool operator !=(EventDefinitionHandle left, EventDefinitionHandle right) 1096 { 1097 return left._rowId != right._rowId; 1098 } 1099 } 1100 1101 public readonly struct PropertyDefinitionHandle : IEquatable<PropertyDefinitionHandle> 1102 { 1103 private const uint tokenType = TokenTypeIds.Property; 1104 private const byte tokenTypeSmall = (byte)HandleType.Property; 1105 private readonly int _rowId; 1106 PropertyDefinitionHandleSystem.Reflection.Metadata.PropertyDefinitionHandle1107 private PropertyDefinitionHandle(int rowId) 1108 { 1109 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1110 _rowId = rowId; 1111 } 1112 FromRowIdSystem.Reflection.Metadata.PropertyDefinitionHandle1113 internal static PropertyDefinitionHandle FromRowId(int rowId) 1114 { 1115 return new PropertyDefinitionHandle(rowId); 1116 } 1117 operator HandleSystem.Reflection.Metadata.PropertyDefinitionHandle1118 public static implicit operator Handle(PropertyDefinitionHandle handle) 1119 { 1120 return new Handle(tokenTypeSmall, handle._rowId); 1121 } 1122 operator EntityHandleSystem.Reflection.Metadata.PropertyDefinitionHandle1123 public static implicit operator EntityHandle(PropertyDefinitionHandle handle) 1124 { 1125 return new EntityHandle((uint)(tokenType | handle._rowId)); 1126 } 1127 operator PropertyDefinitionHandleSystem.Reflection.Metadata.PropertyDefinitionHandle1128 public static explicit operator PropertyDefinitionHandle(Handle handle) 1129 { 1130 if (handle.VType != tokenTypeSmall) 1131 { 1132 Throw.InvalidCast(); 1133 } 1134 1135 return new PropertyDefinitionHandle(handle.RowId); 1136 } 1137 operator PropertyDefinitionHandleSystem.Reflection.Metadata.PropertyDefinitionHandle1138 public static explicit operator PropertyDefinitionHandle(EntityHandle handle) 1139 { 1140 if (handle.VType != tokenType) 1141 { 1142 Throw.InvalidCast(); 1143 } 1144 1145 return new PropertyDefinitionHandle(handle.RowId); 1146 } 1147 1148 public bool IsNil 1149 { 1150 get 1151 { 1152 return RowId == 0; 1153 } 1154 } 1155 1156 internal int RowId { get { return _rowId; } } 1157 operator ==System.Reflection.Metadata.PropertyDefinitionHandle1158 public static bool operator ==(PropertyDefinitionHandle left, PropertyDefinitionHandle right) 1159 { 1160 return left._rowId == right._rowId; 1161 } 1162 EqualsSystem.Reflection.Metadata.PropertyDefinitionHandle1163 public override bool Equals(object obj) 1164 { 1165 return obj is PropertyDefinitionHandle && ((PropertyDefinitionHandle)obj)._rowId == _rowId; 1166 } 1167 EqualsSystem.Reflection.Metadata.PropertyDefinitionHandle1168 public bool Equals(PropertyDefinitionHandle other) 1169 { 1170 return _rowId == other._rowId; 1171 } 1172 GetHashCodeSystem.Reflection.Metadata.PropertyDefinitionHandle1173 public override int GetHashCode() 1174 { 1175 return _rowId.GetHashCode(); 1176 } 1177 operator !=System.Reflection.Metadata.PropertyDefinitionHandle1178 public static bool operator !=(PropertyDefinitionHandle left, PropertyDefinitionHandle right) 1179 { 1180 return left._rowId != right._rowId; 1181 } 1182 } 1183 1184 public readonly struct StandaloneSignatureHandle : IEquatable<StandaloneSignatureHandle> 1185 { 1186 private const uint tokenType = TokenTypeIds.Signature; 1187 private const byte tokenTypeSmall = (byte)HandleType.Signature; 1188 private readonly int _rowId; 1189 StandaloneSignatureHandleSystem.Reflection.Metadata.StandaloneSignatureHandle1190 private StandaloneSignatureHandle(int rowId) 1191 { 1192 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1193 _rowId = rowId; 1194 } 1195 FromRowIdSystem.Reflection.Metadata.StandaloneSignatureHandle1196 internal static StandaloneSignatureHandle FromRowId(int rowId) 1197 { 1198 return new StandaloneSignatureHandle(rowId); 1199 } 1200 operator HandleSystem.Reflection.Metadata.StandaloneSignatureHandle1201 public static implicit operator Handle(StandaloneSignatureHandle handle) 1202 { 1203 return new Handle(tokenTypeSmall, handle._rowId); 1204 } 1205 operator EntityHandleSystem.Reflection.Metadata.StandaloneSignatureHandle1206 public static implicit operator EntityHandle(StandaloneSignatureHandle handle) 1207 { 1208 return new EntityHandle((uint)(tokenType | handle._rowId)); 1209 } 1210 operator StandaloneSignatureHandleSystem.Reflection.Metadata.StandaloneSignatureHandle1211 public static explicit operator StandaloneSignatureHandle(Handle handle) 1212 { 1213 if (handle.VType != tokenTypeSmall) 1214 { 1215 Throw.InvalidCast(); 1216 } 1217 1218 return new StandaloneSignatureHandle(handle.RowId); 1219 } 1220 operator StandaloneSignatureHandleSystem.Reflection.Metadata.StandaloneSignatureHandle1221 public static explicit operator StandaloneSignatureHandle(EntityHandle handle) 1222 { 1223 if (handle.VType != tokenType) 1224 { 1225 Throw.InvalidCast(); 1226 } 1227 1228 return new StandaloneSignatureHandle(handle.RowId); 1229 } 1230 1231 public bool IsNil 1232 { 1233 get 1234 { 1235 return RowId == 0; 1236 } 1237 } 1238 1239 internal int RowId { get { return _rowId; } } 1240 operator ==System.Reflection.Metadata.StandaloneSignatureHandle1241 public static bool operator ==(StandaloneSignatureHandle left, StandaloneSignatureHandle right) 1242 { 1243 return left._rowId == right._rowId; 1244 } 1245 EqualsSystem.Reflection.Metadata.StandaloneSignatureHandle1246 public override bool Equals(object obj) 1247 { 1248 return obj is StandaloneSignatureHandle && ((StandaloneSignatureHandle)obj)._rowId == _rowId; 1249 } 1250 EqualsSystem.Reflection.Metadata.StandaloneSignatureHandle1251 public bool Equals(StandaloneSignatureHandle other) 1252 { 1253 return _rowId == other._rowId; 1254 } 1255 GetHashCodeSystem.Reflection.Metadata.StandaloneSignatureHandle1256 public override int GetHashCode() 1257 { 1258 return _rowId.GetHashCode(); 1259 } 1260 operator !=System.Reflection.Metadata.StandaloneSignatureHandle1261 public static bool operator !=(StandaloneSignatureHandle left, StandaloneSignatureHandle right) 1262 { 1263 return left._rowId != right._rowId; 1264 } 1265 } 1266 1267 public readonly struct ParameterHandle : IEquatable<ParameterHandle> 1268 { 1269 private const uint tokenType = TokenTypeIds.ParamDef; 1270 private const byte tokenTypeSmall = (byte)HandleType.ParamDef; 1271 private readonly int _rowId; 1272 ParameterHandleSystem.Reflection.Metadata.ParameterHandle1273 private ParameterHandle(int rowId) 1274 { 1275 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1276 _rowId = rowId; 1277 } 1278 FromRowIdSystem.Reflection.Metadata.ParameterHandle1279 internal static ParameterHandle FromRowId(int rowId) 1280 { 1281 return new ParameterHandle(rowId); 1282 } 1283 operator HandleSystem.Reflection.Metadata.ParameterHandle1284 public static implicit operator Handle(ParameterHandle handle) 1285 { 1286 return new Handle(tokenTypeSmall, handle._rowId); 1287 } 1288 operator EntityHandleSystem.Reflection.Metadata.ParameterHandle1289 public static implicit operator EntityHandle(ParameterHandle handle) 1290 { 1291 return new EntityHandle((uint)(tokenType | handle._rowId)); 1292 } 1293 operator ParameterHandleSystem.Reflection.Metadata.ParameterHandle1294 public static explicit operator ParameterHandle(Handle handle) 1295 { 1296 if (handle.VType != tokenTypeSmall) 1297 { 1298 Throw.InvalidCast(); 1299 } 1300 1301 return new ParameterHandle(handle.RowId); 1302 } 1303 operator ParameterHandleSystem.Reflection.Metadata.ParameterHandle1304 public static explicit operator ParameterHandle(EntityHandle handle) 1305 { 1306 if (handle.VType != tokenType) 1307 { 1308 Throw.InvalidCast(); 1309 } 1310 1311 return new ParameterHandle(handle.RowId); 1312 } 1313 1314 public bool IsNil 1315 { 1316 get 1317 { 1318 return RowId == 0; 1319 } 1320 } 1321 1322 internal int RowId { get { return _rowId; } } 1323 operator ==System.Reflection.Metadata.ParameterHandle1324 public static bool operator ==(ParameterHandle left, ParameterHandle right) 1325 { 1326 return left._rowId == right._rowId; 1327 } 1328 EqualsSystem.Reflection.Metadata.ParameterHandle1329 public override bool Equals(object obj) 1330 { 1331 return obj is ParameterHandle && ((ParameterHandle)obj)._rowId == _rowId; 1332 } 1333 EqualsSystem.Reflection.Metadata.ParameterHandle1334 public bool Equals(ParameterHandle other) 1335 { 1336 return _rowId == other._rowId; 1337 } 1338 GetHashCodeSystem.Reflection.Metadata.ParameterHandle1339 public override int GetHashCode() 1340 { 1341 return _rowId.GetHashCode(); 1342 } 1343 operator !=System.Reflection.Metadata.ParameterHandle1344 public static bool operator !=(ParameterHandle left, ParameterHandle right) 1345 { 1346 return left._rowId != right._rowId; 1347 } 1348 } 1349 1350 public readonly struct GenericParameterHandle : IEquatable<GenericParameterHandle> 1351 { 1352 private const uint tokenType = TokenTypeIds.GenericParam; 1353 private const byte tokenTypeSmall = (byte)HandleType.GenericParam; 1354 private readonly int _rowId; 1355 GenericParameterHandleSystem.Reflection.Metadata.GenericParameterHandle1356 private GenericParameterHandle(int rowId) 1357 { 1358 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1359 _rowId = rowId; 1360 } 1361 FromRowIdSystem.Reflection.Metadata.GenericParameterHandle1362 internal static GenericParameterHandle FromRowId(int rowId) 1363 { 1364 return new GenericParameterHandle(rowId); 1365 } 1366 operator HandleSystem.Reflection.Metadata.GenericParameterHandle1367 public static implicit operator Handle(GenericParameterHandle handle) 1368 { 1369 return new Handle(tokenTypeSmall, handle._rowId); 1370 } 1371 operator EntityHandleSystem.Reflection.Metadata.GenericParameterHandle1372 public static implicit operator EntityHandle(GenericParameterHandle handle) 1373 { 1374 return new EntityHandle((uint)(tokenType | handle._rowId)); 1375 } 1376 operator GenericParameterHandleSystem.Reflection.Metadata.GenericParameterHandle1377 public static explicit operator GenericParameterHandle(Handle handle) 1378 { 1379 if (handle.VType != tokenTypeSmall) 1380 { 1381 Throw.InvalidCast(); 1382 } 1383 1384 return new GenericParameterHandle(handle.RowId); 1385 } 1386 operator GenericParameterHandleSystem.Reflection.Metadata.GenericParameterHandle1387 public static explicit operator GenericParameterHandle(EntityHandle handle) 1388 { 1389 if (handle.VType != tokenType) 1390 { 1391 Throw.InvalidCast(); 1392 } 1393 1394 return new GenericParameterHandle(handle.RowId); 1395 } 1396 1397 public bool IsNil 1398 { 1399 get 1400 { 1401 return RowId == 0; 1402 } 1403 } 1404 1405 internal int RowId { get { return _rowId; } } 1406 operator ==System.Reflection.Metadata.GenericParameterHandle1407 public static bool operator ==(GenericParameterHandle left, GenericParameterHandle right) 1408 { 1409 return left._rowId == right._rowId; 1410 } 1411 EqualsSystem.Reflection.Metadata.GenericParameterHandle1412 public override bool Equals(object obj) 1413 { 1414 return obj is GenericParameterHandle && ((GenericParameterHandle)obj)._rowId == _rowId; 1415 } 1416 EqualsSystem.Reflection.Metadata.GenericParameterHandle1417 public bool Equals(GenericParameterHandle other) 1418 { 1419 return _rowId == other._rowId; 1420 } 1421 GetHashCodeSystem.Reflection.Metadata.GenericParameterHandle1422 public override int GetHashCode() 1423 { 1424 return _rowId.GetHashCode(); 1425 } 1426 operator !=System.Reflection.Metadata.GenericParameterHandle1427 public static bool operator !=(GenericParameterHandle left, GenericParameterHandle right) 1428 { 1429 return left._rowId != right._rowId; 1430 } 1431 } 1432 1433 public readonly struct GenericParameterConstraintHandle : IEquatable<GenericParameterConstraintHandle> 1434 { 1435 private const uint tokenType = TokenTypeIds.GenericParamConstraint; 1436 private const byte tokenTypeSmall = (byte)HandleType.GenericParamConstraint; 1437 private readonly int _rowId; 1438 GenericParameterConstraintHandleSystem.Reflection.Metadata.GenericParameterConstraintHandle1439 private GenericParameterConstraintHandle(int rowId) 1440 { 1441 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1442 _rowId = rowId; 1443 } 1444 FromRowIdSystem.Reflection.Metadata.GenericParameterConstraintHandle1445 internal static GenericParameterConstraintHandle FromRowId(int rowId) 1446 { 1447 return new GenericParameterConstraintHandle(rowId); 1448 } 1449 operator HandleSystem.Reflection.Metadata.GenericParameterConstraintHandle1450 public static implicit operator Handle(GenericParameterConstraintHandle handle) 1451 { 1452 return new Handle(tokenTypeSmall, handle._rowId); 1453 } 1454 operator EntityHandleSystem.Reflection.Metadata.GenericParameterConstraintHandle1455 public static implicit operator EntityHandle(GenericParameterConstraintHandle handle) 1456 { 1457 return new EntityHandle((uint)(tokenType | handle._rowId)); 1458 } 1459 operator GenericParameterConstraintHandleSystem.Reflection.Metadata.GenericParameterConstraintHandle1460 public static explicit operator GenericParameterConstraintHandle(Handle handle) 1461 { 1462 if (handle.VType != tokenTypeSmall) 1463 { 1464 Throw.InvalidCast(); 1465 } 1466 1467 return new GenericParameterConstraintHandle(handle.RowId); 1468 } 1469 operator GenericParameterConstraintHandleSystem.Reflection.Metadata.GenericParameterConstraintHandle1470 public static explicit operator GenericParameterConstraintHandle(EntityHandle handle) 1471 { 1472 if (handle.VType != tokenType) 1473 { 1474 Throw.InvalidCast(); 1475 } 1476 1477 return new GenericParameterConstraintHandle(handle.RowId); 1478 } 1479 1480 public bool IsNil 1481 { 1482 get 1483 { 1484 return RowId == 0; 1485 } 1486 } 1487 1488 internal int RowId { get { return _rowId; } } 1489 operator ==System.Reflection.Metadata.GenericParameterConstraintHandle1490 public static bool operator ==(GenericParameterConstraintHandle left, GenericParameterConstraintHandle right) 1491 { 1492 return left._rowId == right._rowId; 1493 } 1494 EqualsSystem.Reflection.Metadata.GenericParameterConstraintHandle1495 public override bool Equals(object obj) 1496 { 1497 return obj is GenericParameterConstraintHandle && ((GenericParameterConstraintHandle)obj)._rowId == _rowId; 1498 } 1499 EqualsSystem.Reflection.Metadata.GenericParameterConstraintHandle1500 public bool Equals(GenericParameterConstraintHandle other) 1501 { 1502 return _rowId == other._rowId; 1503 } 1504 GetHashCodeSystem.Reflection.Metadata.GenericParameterConstraintHandle1505 public override int GetHashCode() 1506 { 1507 return _rowId.GetHashCode(); 1508 } 1509 operator !=System.Reflection.Metadata.GenericParameterConstraintHandle1510 public static bool operator !=(GenericParameterConstraintHandle left, GenericParameterConstraintHandle right) 1511 { 1512 return left._rowId != right._rowId; 1513 } 1514 } 1515 1516 public readonly struct ModuleReferenceHandle : IEquatable<ModuleReferenceHandle> 1517 { 1518 private const uint tokenType = TokenTypeIds.ModuleRef; 1519 private const byte tokenTypeSmall = (byte)HandleType.ModuleRef; 1520 private readonly int _rowId; 1521 ModuleReferenceHandleSystem.Reflection.Metadata.ModuleReferenceHandle1522 private ModuleReferenceHandle(int rowId) 1523 { 1524 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1525 _rowId = rowId; 1526 } 1527 FromRowIdSystem.Reflection.Metadata.ModuleReferenceHandle1528 internal static ModuleReferenceHandle FromRowId(int rowId) 1529 { 1530 return new ModuleReferenceHandle(rowId); 1531 } 1532 operator HandleSystem.Reflection.Metadata.ModuleReferenceHandle1533 public static implicit operator Handle(ModuleReferenceHandle handle) 1534 { 1535 return new Handle(tokenTypeSmall, handle._rowId); 1536 } 1537 operator EntityHandleSystem.Reflection.Metadata.ModuleReferenceHandle1538 public static implicit operator EntityHandle(ModuleReferenceHandle handle) 1539 { 1540 return new EntityHandle((uint)(tokenType | handle._rowId)); 1541 } 1542 operator ModuleReferenceHandleSystem.Reflection.Metadata.ModuleReferenceHandle1543 public static explicit operator ModuleReferenceHandle(Handle handle) 1544 { 1545 if (handle.VType != tokenTypeSmall) 1546 { 1547 Throw.InvalidCast(); 1548 } 1549 1550 return new ModuleReferenceHandle(handle.RowId); 1551 } 1552 operator ModuleReferenceHandleSystem.Reflection.Metadata.ModuleReferenceHandle1553 public static explicit operator ModuleReferenceHandle(EntityHandle handle) 1554 { 1555 if (handle.VType != tokenType) 1556 { 1557 Throw.InvalidCast(); 1558 } 1559 1560 return new ModuleReferenceHandle(handle.RowId); 1561 } 1562 1563 public bool IsNil 1564 { 1565 get 1566 { 1567 return RowId == 0; 1568 } 1569 } 1570 1571 internal int RowId { get { return _rowId; } } 1572 operator ==System.Reflection.Metadata.ModuleReferenceHandle1573 public static bool operator ==(ModuleReferenceHandle left, ModuleReferenceHandle right) 1574 { 1575 return left._rowId == right._rowId; 1576 } 1577 EqualsSystem.Reflection.Metadata.ModuleReferenceHandle1578 public override bool Equals(object obj) 1579 { 1580 return obj is ModuleReferenceHandle && ((ModuleReferenceHandle)obj)._rowId == _rowId; 1581 } 1582 EqualsSystem.Reflection.Metadata.ModuleReferenceHandle1583 public bool Equals(ModuleReferenceHandle other) 1584 { 1585 return _rowId == other._rowId; 1586 } 1587 GetHashCodeSystem.Reflection.Metadata.ModuleReferenceHandle1588 public override int GetHashCode() 1589 { 1590 return _rowId.GetHashCode(); 1591 } 1592 operator !=System.Reflection.Metadata.ModuleReferenceHandle1593 public static bool operator !=(ModuleReferenceHandle left, ModuleReferenceHandle right) 1594 { 1595 return left._rowId != right._rowId; 1596 } 1597 } 1598 1599 public readonly struct AssemblyReferenceHandle : IEquatable<AssemblyReferenceHandle> 1600 { 1601 private const uint tokenType = TokenTypeIds.AssemblyRef; 1602 private const byte tokenTypeSmall = (byte)HandleType.AssemblyRef; 1603 1604 // bits: 1605 // 31: IsVirtual 1606 // 24..30: 0 1607 // 0..23: Heap offset or Virtual index 1608 private readonly uint _value; 1609 1610 internal enum VirtualIndex 1611 { 1612 System_Runtime, 1613 System_Runtime_InteropServices_WindowsRuntime, 1614 System_ObjectModel, 1615 System_Runtime_WindowsRuntime, 1616 System_Runtime_WindowsRuntime_UI_Xaml, 1617 System_Numerics_Vectors, 1618 1619 Count 1620 } 1621 AssemblyReferenceHandleSystem.Reflection.Metadata.AssemblyReferenceHandle1622 private AssemblyReferenceHandle(uint value) 1623 { 1624 _value = value; 1625 } 1626 FromRowIdSystem.Reflection.Metadata.AssemblyReferenceHandle1627 internal static AssemblyReferenceHandle FromRowId(int rowId) 1628 { 1629 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1630 return new AssemblyReferenceHandle((uint)rowId); 1631 } 1632 FromVirtualIndexSystem.Reflection.Metadata.AssemblyReferenceHandle1633 internal static AssemblyReferenceHandle FromVirtualIndex(VirtualIndex virtualIndex) 1634 { 1635 Debug.Assert(virtualIndex < VirtualIndex.Count); 1636 return new AssemblyReferenceHandle(TokenTypeIds.VirtualBit | (uint)virtualIndex); 1637 } 1638 operator HandleSystem.Reflection.Metadata.AssemblyReferenceHandle1639 public static implicit operator Handle(AssemblyReferenceHandle handle) 1640 { 1641 return Handle.FromVToken(handle.VToken); 1642 } 1643 operator EntityHandleSystem.Reflection.Metadata.AssemblyReferenceHandle1644 public static implicit operator EntityHandle(AssemblyReferenceHandle handle) 1645 { 1646 return new EntityHandle(handle.VToken); 1647 } 1648 operator AssemblyReferenceHandleSystem.Reflection.Metadata.AssemblyReferenceHandle1649 public static explicit operator AssemblyReferenceHandle(Handle handle) 1650 { 1651 if (handle.Type != tokenTypeSmall) 1652 { 1653 Throw.InvalidCast(); 1654 } 1655 1656 return new AssemblyReferenceHandle(handle.SpecificEntityHandleValue); 1657 } 1658 operator AssemblyReferenceHandleSystem.Reflection.Metadata.AssemblyReferenceHandle1659 public static explicit operator AssemblyReferenceHandle(EntityHandle handle) 1660 { 1661 if (handle.Type != tokenType) 1662 { 1663 Throw.InvalidCast(); 1664 } 1665 1666 return new AssemblyReferenceHandle(handle.SpecificHandleValue); 1667 } 1668 1669 internal uint Value 1670 { 1671 get { return _value; } 1672 } 1673 1674 private uint VToken 1675 { 1676 get { return _value | tokenType; } 1677 } 1678 1679 public bool IsNil 1680 { 1681 get { return _value == 0; } 1682 } 1683 1684 internal bool IsVirtual 1685 { 1686 get { return (_value & TokenTypeIds.VirtualBit) != 0; } 1687 } 1688 1689 internal int RowId { get { return (int)(_value & TokenTypeIds.RIDMask); } } 1690 operator ==System.Reflection.Metadata.AssemblyReferenceHandle1691 public static bool operator ==(AssemblyReferenceHandle left, AssemblyReferenceHandle right) 1692 { 1693 return left._value == right._value; 1694 } 1695 EqualsSystem.Reflection.Metadata.AssemblyReferenceHandle1696 public override bool Equals(object obj) 1697 { 1698 return obj is AssemblyReferenceHandle && ((AssemblyReferenceHandle)obj)._value == _value; 1699 } 1700 EqualsSystem.Reflection.Metadata.AssemblyReferenceHandle1701 public bool Equals(AssemblyReferenceHandle other) 1702 { 1703 return _value == other._value; 1704 } 1705 GetHashCodeSystem.Reflection.Metadata.AssemblyReferenceHandle1706 public override int GetHashCode() 1707 { 1708 return _value.GetHashCode(); 1709 } 1710 operator !=System.Reflection.Metadata.AssemblyReferenceHandle1711 public static bool operator !=(AssemblyReferenceHandle left, AssemblyReferenceHandle right) 1712 { 1713 return left._value != right._value; 1714 } 1715 } 1716 1717 public readonly struct CustomAttributeHandle : IEquatable<CustomAttributeHandle> 1718 { 1719 private const uint tokenType = TokenTypeIds.CustomAttribute; 1720 private const byte tokenTypeSmall = (byte)HandleType.CustomAttribute; 1721 private readonly int _rowId; 1722 CustomAttributeHandleSystem.Reflection.Metadata.CustomAttributeHandle1723 private CustomAttributeHandle(int rowId) 1724 { 1725 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1726 _rowId = rowId; 1727 } 1728 FromRowIdSystem.Reflection.Metadata.CustomAttributeHandle1729 internal static CustomAttributeHandle FromRowId(int rowId) 1730 { 1731 return new CustomAttributeHandle(rowId); 1732 } 1733 operator HandleSystem.Reflection.Metadata.CustomAttributeHandle1734 public static implicit operator Handle(CustomAttributeHandle handle) 1735 { 1736 return new Handle(tokenTypeSmall, handle._rowId); 1737 } 1738 operator EntityHandleSystem.Reflection.Metadata.CustomAttributeHandle1739 public static implicit operator EntityHandle(CustomAttributeHandle handle) 1740 { 1741 return new EntityHandle((uint)(tokenType | handle._rowId)); 1742 } 1743 operator CustomAttributeHandleSystem.Reflection.Metadata.CustomAttributeHandle1744 public static explicit operator CustomAttributeHandle(Handle handle) 1745 { 1746 if (handle.VType != tokenTypeSmall) 1747 { 1748 Throw.InvalidCast(); 1749 } 1750 1751 return new CustomAttributeHandle(handle.RowId); 1752 } 1753 operator CustomAttributeHandleSystem.Reflection.Metadata.CustomAttributeHandle1754 public static explicit operator CustomAttributeHandle(EntityHandle handle) 1755 { 1756 if (handle.VType != tokenType) 1757 { 1758 Throw.InvalidCast(); 1759 } 1760 1761 return new CustomAttributeHandle(handle.RowId); 1762 } 1763 1764 public bool IsNil 1765 { 1766 get 1767 { 1768 return _rowId == 0; 1769 } 1770 } 1771 1772 internal int RowId { get { return _rowId; } } 1773 operator ==System.Reflection.Metadata.CustomAttributeHandle1774 public static bool operator ==(CustomAttributeHandle left, CustomAttributeHandle right) 1775 { 1776 return left._rowId == right._rowId; 1777 } 1778 EqualsSystem.Reflection.Metadata.CustomAttributeHandle1779 public override bool Equals(object obj) 1780 { 1781 return obj is CustomAttributeHandle && ((CustomAttributeHandle)obj)._rowId == _rowId; 1782 } 1783 EqualsSystem.Reflection.Metadata.CustomAttributeHandle1784 public bool Equals(CustomAttributeHandle other) 1785 { 1786 return _rowId == other._rowId; 1787 } 1788 GetHashCodeSystem.Reflection.Metadata.CustomAttributeHandle1789 public override int GetHashCode() 1790 { 1791 return _rowId.GetHashCode(); 1792 } 1793 operator !=System.Reflection.Metadata.CustomAttributeHandle1794 public static bool operator !=(CustomAttributeHandle left, CustomAttributeHandle right) 1795 { 1796 return left._rowId != right._rowId; 1797 } 1798 } 1799 1800 public readonly struct DeclarativeSecurityAttributeHandle : IEquatable<DeclarativeSecurityAttributeHandle> 1801 { 1802 private const uint tokenType = TokenTypeIds.DeclSecurity; 1803 private const byte tokenTypeSmall = (byte)HandleType.DeclSecurity; 1804 private readonly int _rowId; 1805 DeclarativeSecurityAttributeHandleSystem.Reflection.Metadata.DeclarativeSecurityAttributeHandle1806 private DeclarativeSecurityAttributeHandle(int rowId) 1807 { 1808 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1809 _rowId = rowId; 1810 } 1811 FromRowIdSystem.Reflection.Metadata.DeclarativeSecurityAttributeHandle1812 internal static DeclarativeSecurityAttributeHandle FromRowId(int rowId) 1813 { 1814 return new DeclarativeSecurityAttributeHandle(rowId); 1815 } 1816 operator HandleSystem.Reflection.Metadata.DeclarativeSecurityAttributeHandle1817 public static implicit operator Handle(DeclarativeSecurityAttributeHandle handle) 1818 { 1819 return new Handle(tokenTypeSmall, handle._rowId); 1820 } 1821 operator EntityHandleSystem.Reflection.Metadata.DeclarativeSecurityAttributeHandle1822 public static implicit operator EntityHandle(DeclarativeSecurityAttributeHandle handle) 1823 { 1824 return new EntityHandle((uint)(tokenType | handle._rowId)); 1825 } 1826 operator DeclarativeSecurityAttributeHandleSystem.Reflection.Metadata.DeclarativeSecurityAttributeHandle1827 public static explicit operator DeclarativeSecurityAttributeHandle(Handle handle) 1828 { 1829 if (handle.VType != tokenTypeSmall) 1830 { 1831 Throw.InvalidCast(); 1832 } 1833 1834 return new DeclarativeSecurityAttributeHandle(handle.RowId); 1835 } 1836 operator DeclarativeSecurityAttributeHandleSystem.Reflection.Metadata.DeclarativeSecurityAttributeHandle1837 public static explicit operator DeclarativeSecurityAttributeHandle(EntityHandle handle) 1838 { 1839 if (handle.VType != tokenType) 1840 { 1841 Throw.InvalidCast(); 1842 } 1843 1844 return new DeclarativeSecurityAttributeHandle(handle.RowId); 1845 } 1846 1847 public bool IsNil 1848 { 1849 get 1850 { 1851 return _rowId == 0; 1852 } 1853 } 1854 1855 internal int RowId { get { return _rowId; } } 1856 operator ==System.Reflection.Metadata.DeclarativeSecurityAttributeHandle1857 public static bool operator ==(DeclarativeSecurityAttributeHandle left, DeclarativeSecurityAttributeHandle right) 1858 { 1859 return left._rowId == right._rowId; 1860 } 1861 EqualsSystem.Reflection.Metadata.DeclarativeSecurityAttributeHandle1862 public override bool Equals(object obj) 1863 { 1864 return obj is DeclarativeSecurityAttributeHandle && ((DeclarativeSecurityAttributeHandle)obj)._rowId == _rowId; 1865 } 1866 EqualsSystem.Reflection.Metadata.DeclarativeSecurityAttributeHandle1867 public bool Equals(DeclarativeSecurityAttributeHandle other) 1868 { 1869 return _rowId == other._rowId; 1870 } 1871 GetHashCodeSystem.Reflection.Metadata.DeclarativeSecurityAttributeHandle1872 public override int GetHashCode() 1873 { 1874 return _rowId.GetHashCode(); 1875 } 1876 operator !=System.Reflection.Metadata.DeclarativeSecurityAttributeHandle1877 public static bool operator !=(DeclarativeSecurityAttributeHandle left, DeclarativeSecurityAttributeHandle right) 1878 { 1879 return left._rowId != right._rowId; 1880 } 1881 } 1882 1883 public readonly struct ConstantHandle : IEquatable<ConstantHandle> 1884 { 1885 private const uint tokenType = TokenTypeIds.Constant; 1886 private const byte tokenTypeSmall = (byte)HandleType.Constant; 1887 private readonly int _rowId; 1888 ConstantHandleSystem.Reflection.Metadata.ConstantHandle1889 private ConstantHandle(int rowId) 1890 { 1891 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1892 _rowId = rowId; 1893 } 1894 FromRowIdSystem.Reflection.Metadata.ConstantHandle1895 internal static ConstantHandle FromRowId(int rowId) 1896 { 1897 return new ConstantHandle(rowId); 1898 } 1899 operator HandleSystem.Reflection.Metadata.ConstantHandle1900 public static implicit operator Handle(ConstantHandle handle) 1901 { 1902 return new Handle(tokenTypeSmall, handle._rowId); 1903 } 1904 operator EntityHandleSystem.Reflection.Metadata.ConstantHandle1905 public static implicit operator EntityHandle(ConstantHandle handle) 1906 { 1907 return new EntityHandle((uint)(tokenType | handle._rowId)); 1908 } 1909 operator ConstantHandleSystem.Reflection.Metadata.ConstantHandle1910 public static explicit operator ConstantHandle(Handle handle) 1911 { 1912 if (handle.VType != tokenTypeSmall) 1913 { 1914 Throw.InvalidCast(); 1915 } 1916 1917 return new ConstantHandle(handle.RowId); 1918 } 1919 operator ConstantHandleSystem.Reflection.Metadata.ConstantHandle1920 public static explicit operator ConstantHandle(EntityHandle handle) 1921 { 1922 if (handle.VType != tokenType) 1923 { 1924 Throw.InvalidCast(); 1925 } 1926 1927 return new ConstantHandle(handle.RowId); 1928 } 1929 1930 public bool IsNil 1931 { 1932 get 1933 { 1934 return RowId == 0; 1935 } 1936 } 1937 1938 internal int RowId { get { return _rowId; } } 1939 operator ==System.Reflection.Metadata.ConstantHandle1940 public static bool operator ==(ConstantHandle left, ConstantHandle right) 1941 { 1942 return left._rowId == right._rowId; 1943 } 1944 EqualsSystem.Reflection.Metadata.ConstantHandle1945 public override bool Equals(object obj) 1946 { 1947 return obj is ConstantHandle && ((ConstantHandle)obj)._rowId == _rowId; 1948 } 1949 EqualsSystem.Reflection.Metadata.ConstantHandle1950 public bool Equals(ConstantHandle other) 1951 { 1952 return _rowId == other._rowId; 1953 } 1954 GetHashCodeSystem.Reflection.Metadata.ConstantHandle1955 public override int GetHashCode() 1956 { 1957 return _rowId.GetHashCode(); 1958 } 1959 operator !=System.Reflection.Metadata.ConstantHandle1960 public static bool operator !=(ConstantHandle left, ConstantHandle right) 1961 { 1962 return left._rowId != right._rowId; 1963 } 1964 } 1965 1966 public readonly struct ManifestResourceHandle : IEquatable<ManifestResourceHandle> 1967 { 1968 private const uint tokenType = TokenTypeIds.ManifestResource; 1969 private const byte tokenTypeSmall = (byte)HandleType.ManifestResource; 1970 private readonly int _rowId; 1971 ManifestResourceHandleSystem.Reflection.Metadata.ManifestResourceHandle1972 private ManifestResourceHandle(int rowId) 1973 { 1974 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 1975 _rowId = rowId; 1976 } 1977 FromRowIdSystem.Reflection.Metadata.ManifestResourceHandle1978 internal static ManifestResourceHandle FromRowId(int rowId) 1979 { 1980 return new ManifestResourceHandle(rowId); 1981 } 1982 operator HandleSystem.Reflection.Metadata.ManifestResourceHandle1983 public static implicit operator Handle(ManifestResourceHandle handle) 1984 { 1985 return new Handle(tokenTypeSmall, handle._rowId); 1986 } 1987 operator EntityHandleSystem.Reflection.Metadata.ManifestResourceHandle1988 public static implicit operator EntityHandle(ManifestResourceHandle handle) 1989 { 1990 return new EntityHandle((uint)(tokenType | handle._rowId)); 1991 } 1992 operator ManifestResourceHandleSystem.Reflection.Metadata.ManifestResourceHandle1993 public static explicit operator ManifestResourceHandle(Handle handle) 1994 { 1995 if (handle.VType != tokenTypeSmall) 1996 { 1997 Throw.InvalidCast(); 1998 } 1999 2000 return new ManifestResourceHandle(handle.RowId); 2001 } 2002 operator ManifestResourceHandleSystem.Reflection.Metadata.ManifestResourceHandle2003 public static explicit operator ManifestResourceHandle(EntityHandle handle) 2004 { 2005 if (handle.VType != tokenType) 2006 { 2007 Throw.InvalidCast(); 2008 } 2009 2010 return new ManifestResourceHandle(handle.RowId); 2011 } 2012 2013 public bool IsNil 2014 { 2015 get 2016 { 2017 return RowId == 0; 2018 } 2019 } 2020 2021 internal int RowId { get { return _rowId; } } 2022 operator ==System.Reflection.Metadata.ManifestResourceHandle2023 public static bool operator ==(ManifestResourceHandle left, ManifestResourceHandle right) 2024 { 2025 return left._rowId == right._rowId; 2026 } 2027 EqualsSystem.Reflection.Metadata.ManifestResourceHandle2028 public override bool Equals(object obj) 2029 { 2030 return obj is ManifestResourceHandle && ((ManifestResourceHandle)obj)._rowId == _rowId; 2031 } 2032 EqualsSystem.Reflection.Metadata.ManifestResourceHandle2033 public bool Equals(ManifestResourceHandle other) 2034 { 2035 return _rowId == other._rowId; 2036 } 2037 GetHashCodeSystem.Reflection.Metadata.ManifestResourceHandle2038 public override int GetHashCode() 2039 { 2040 return _rowId.GetHashCode(); 2041 } 2042 operator !=System.Reflection.Metadata.ManifestResourceHandle2043 public static bool operator !=(ManifestResourceHandle left, ManifestResourceHandle right) 2044 { 2045 return left._rowId != right._rowId; 2046 } 2047 } 2048 2049 public readonly struct AssemblyFileHandle : IEquatable<AssemblyFileHandle> 2050 { 2051 private const uint tokenType = TokenTypeIds.File; 2052 private const byte tokenTypeSmall = (byte)HandleType.File; 2053 private readonly int _rowId; 2054 AssemblyFileHandleSystem.Reflection.Metadata.AssemblyFileHandle2055 private AssemblyFileHandle(int rowId) 2056 { 2057 Debug.Assert(TokenTypeIds.IsValidRowId(rowId)); 2058 _rowId = rowId; 2059 } 2060 FromRowIdSystem.Reflection.Metadata.AssemblyFileHandle2061 internal static AssemblyFileHandle FromRowId(int rowId) 2062 { 2063 return new AssemblyFileHandle(rowId); 2064 } 2065 operator HandleSystem.Reflection.Metadata.AssemblyFileHandle2066 public static implicit operator Handle(AssemblyFileHandle handle) 2067 { 2068 return new Handle(tokenTypeSmall, handle._rowId); 2069 } 2070 operator EntityHandleSystem.Reflection.Metadata.AssemblyFileHandle2071 public static implicit operator EntityHandle(AssemblyFileHandle handle) 2072 { 2073 return new EntityHandle((uint)(tokenType | handle._rowId)); 2074 } 2075 operator AssemblyFileHandleSystem.Reflection.Metadata.AssemblyFileHandle2076 public static explicit operator AssemblyFileHandle(Handle handle) 2077 { 2078 if (handle.VType != tokenTypeSmall) 2079 { 2080 Throw.InvalidCast(); 2081 } 2082 2083 return new AssemblyFileHandle(handle.RowId); 2084 } 2085 operator AssemblyFileHandleSystem.Reflection.Metadata.AssemblyFileHandle2086 public static explicit operator AssemblyFileHandle(EntityHandle handle) 2087 { 2088 if (handle.VType != tokenType) 2089 { 2090 Throw.InvalidCast(); 2091 } 2092 2093 return new AssemblyFileHandle(handle.RowId); 2094 } 2095 2096 public bool IsNil 2097 { 2098 get 2099 { 2100 return RowId == 0; 2101 } 2102 } 2103 2104 internal int RowId { get { return _rowId; } } 2105 operator ==System.Reflection.Metadata.AssemblyFileHandle2106 public static bool operator ==(AssemblyFileHandle left, AssemblyFileHandle right) 2107 { 2108 return left._rowId == right._rowId; 2109 } 2110 EqualsSystem.Reflection.Metadata.AssemblyFileHandle2111 public override bool Equals(object obj) 2112 { 2113 return obj is AssemblyFileHandle && ((AssemblyFileHandle)obj)._rowId == _rowId; 2114 } 2115 EqualsSystem.Reflection.Metadata.AssemblyFileHandle2116 public bool Equals(AssemblyFileHandle other) 2117 { 2118 return _rowId == other._rowId; 2119 } 2120 GetHashCodeSystem.Reflection.Metadata.AssemblyFileHandle2121 public override int GetHashCode() 2122 { 2123 return _rowId.GetHashCode(); 2124 } 2125 operator !=System.Reflection.Metadata.AssemblyFileHandle2126 public static bool operator !=(AssemblyFileHandle left, AssemblyFileHandle right) 2127 { 2128 return left._rowId != right._rowId; 2129 } 2130 } 2131 2132 /// <summary> 2133 /// #UserString heap handle. 2134 /// </summary> 2135 /// <remarks> 2136 /// The handle is 32-bit wide. 2137 /// </remarks> 2138 public readonly struct UserStringHandle : IEquatable<UserStringHandle> 2139 { 2140 // bits: 2141 // 31: 0 2142 // 24..30: 0 2143 // 0..23: index 2144 private readonly int _offset; 2145 UserStringHandleSystem.Reflection.Metadata.UserStringHandle2146 private UserStringHandle(int offset) 2147 { 2148 // #US string indices must fit into 24bits since they are used in IL stream tokens 2149 Debug.Assert((offset & 0xFF000000) == 0); 2150 _offset = offset; 2151 } 2152 FromOffsetSystem.Reflection.Metadata.UserStringHandle2153 internal static UserStringHandle FromOffset(int heapOffset) 2154 { 2155 return new UserStringHandle(heapOffset); 2156 } 2157 operator HandleSystem.Reflection.Metadata.UserStringHandle2158 public static implicit operator Handle(UserStringHandle handle) 2159 { 2160 return new Handle((byte)HandleType.UserString, handle._offset); 2161 } 2162 operator UserStringHandleSystem.Reflection.Metadata.UserStringHandle2163 public static explicit operator UserStringHandle(Handle handle) 2164 { 2165 if (handle.VType != HandleType.UserString) 2166 { 2167 Throw.InvalidCast(); 2168 } 2169 2170 return new UserStringHandle(handle.Offset); 2171 } 2172 2173 public bool IsNil 2174 { 2175 get { return _offset == 0; } 2176 } 2177 GetHeapOffsetSystem.Reflection.Metadata.UserStringHandle2178 internal int GetHeapOffset() 2179 { 2180 return _offset; 2181 } 2182 operator ==System.Reflection.Metadata.UserStringHandle2183 public static bool operator ==(UserStringHandle left, UserStringHandle right) 2184 { 2185 return left._offset == right._offset; 2186 } 2187 EqualsSystem.Reflection.Metadata.UserStringHandle2188 public override bool Equals(object obj) 2189 { 2190 return obj is UserStringHandle && ((UserStringHandle)obj)._offset == _offset; 2191 } 2192 EqualsSystem.Reflection.Metadata.UserStringHandle2193 public bool Equals(UserStringHandle other) 2194 { 2195 return _offset == other._offset; 2196 } 2197 GetHashCodeSystem.Reflection.Metadata.UserStringHandle2198 public override int GetHashCode() 2199 { 2200 return _offset.GetHashCode(); 2201 } 2202 operator !=System.Reflection.Metadata.UserStringHandle2203 public static bool operator !=(UserStringHandle left, UserStringHandle right) 2204 { 2205 return left._offset != right._offset; 2206 } 2207 } 2208 2209 // #String heap handle 2210 public readonly struct StringHandle : IEquatable<StringHandle> 2211 { 2212 // bits: 2213 // 31: IsVirtual 2214 // 29..31: type (non-virtual: String, DotTerminatedString; virtual: VirtualString, WinRTPrefixedString) 2215 // 0..28: Heap offset or Virtual index 2216 private readonly uint _value; 2217 2218 internal enum VirtualIndex 2219 { 2220 System_Runtime_WindowsRuntime, 2221 System_Runtime, 2222 System_ObjectModel, 2223 System_Runtime_WindowsRuntime_UI_Xaml, 2224 System_Runtime_InteropServices_WindowsRuntime, 2225 System_Numerics_Vectors, 2226 2227 Dispose, 2228 2229 AttributeTargets, 2230 AttributeUsageAttribute, 2231 Color, 2232 CornerRadius, 2233 DateTimeOffset, 2234 Duration, 2235 DurationType, 2236 EventHandler1, 2237 EventRegistrationToken, 2238 Exception, 2239 GeneratorPosition, 2240 GridLength, 2241 GridUnitType, 2242 ICommand, 2243 IDictionary2, 2244 IDisposable, 2245 IEnumerable, 2246 IEnumerable1, 2247 IList, 2248 IList1, 2249 INotifyCollectionChanged, 2250 INotifyPropertyChanged, 2251 IReadOnlyDictionary2, 2252 IReadOnlyList1, 2253 KeyTime, 2254 KeyValuePair2, 2255 Matrix, 2256 Matrix3D, 2257 Matrix3x2, 2258 Matrix4x4, 2259 NotifyCollectionChangedAction, 2260 NotifyCollectionChangedEventArgs, 2261 NotifyCollectionChangedEventHandler, 2262 Nullable1, 2263 Plane, 2264 Point, 2265 PropertyChangedEventArgs, 2266 PropertyChangedEventHandler, 2267 Quaternion, 2268 Rect, 2269 RepeatBehavior, 2270 RepeatBehaviorType, 2271 Size, 2272 System, 2273 System_Collections, 2274 System_Collections_Generic, 2275 System_Collections_Specialized, 2276 System_ComponentModel, 2277 System_Numerics, 2278 System_Windows_Input, 2279 Thickness, 2280 TimeSpan, 2281 Type, 2282 Uri, 2283 Vector2, 2284 Vector3, 2285 Vector4, 2286 Windows_Foundation, 2287 Windows_UI, 2288 Windows_UI_Xaml, 2289 Windows_UI_Xaml_Controls_Primitives, 2290 Windows_UI_Xaml_Media, 2291 Windows_UI_Xaml_Media_Animation, 2292 Windows_UI_Xaml_Media_Media3D, 2293 2294 Count 2295 } 2296 StringHandleSystem.Reflection.Metadata.StringHandle2297 private StringHandle(uint value) 2298 { 2299 Debug.Assert((value & StringHandleType.TypeMask) == StringHandleType.String || 2300 (value & StringHandleType.TypeMask) == StringHandleType.VirtualString || 2301 (value & StringHandleType.TypeMask) == StringHandleType.WinRTPrefixedString || 2302 (value & StringHandleType.TypeMask) == StringHandleType.DotTerminatedString); 2303 2304 _value = value; 2305 } 2306 FromOffsetSystem.Reflection.Metadata.StringHandle2307 internal static StringHandle FromOffset(int heapOffset) 2308 { 2309 return new StringHandle(StringHandleType.String | (uint)heapOffset); 2310 } 2311 FromVirtualIndexSystem.Reflection.Metadata.StringHandle2312 internal static StringHandle FromVirtualIndex(VirtualIndex virtualIndex) 2313 { 2314 Debug.Assert(virtualIndex < VirtualIndex.Count); 2315 return new StringHandle(StringHandleType.VirtualString | (uint)virtualIndex); 2316 } 2317 FromWriterVirtualIndexSystem.Reflection.Metadata.StringHandle2318 internal static StringHandle FromWriterVirtualIndex(int virtualIndex) 2319 { 2320 return new StringHandle(StringHandleType.VirtualString | (uint)virtualIndex); 2321 } 2322 WithWinRTPrefixSystem.Reflection.Metadata.StringHandle2323 internal StringHandle WithWinRTPrefix() 2324 { 2325 Debug.Assert(StringKind == StringKind.Plain); 2326 return new StringHandle(StringHandleType.WinRTPrefixedString | _value); 2327 } 2328 WithDotTerminationSystem.Reflection.Metadata.StringHandle2329 internal StringHandle WithDotTermination() 2330 { 2331 Debug.Assert(StringKind == StringKind.Plain); 2332 return new StringHandle(StringHandleType.DotTerminatedString | _value); 2333 } 2334 SuffixRawSystem.Reflection.Metadata.StringHandle2335 internal StringHandle SuffixRaw(int prefixByteLength) 2336 { 2337 Debug.Assert(StringKind == StringKind.Plain); 2338 Debug.Assert(prefixByteLength >= 0); 2339 return new StringHandle(StringHandleType.String | (_value + (uint)prefixByteLength)); 2340 } 2341 operator HandleSystem.Reflection.Metadata.StringHandle2342 public static implicit operator Handle(StringHandle handle) 2343 { 2344 // VTTx xxxx xxxx xxxx xxxx xxxx xxxx xxxx -> V111 10TT 2345 return new Handle( 2346 (byte)((handle._value & HeapHandleType.VirtualBit) >> 24 | HandleType.String | (handle._value & StringHandleType.NonVirtualTypeMask) >> HeapHandleType.OffsetBitCount), 2347 (int)(handle._value & HeapHandleType.OffsetMask)); 2348 } 2349 operator StringHandleSystem.Reflection.Metadata.StringHandle2350 public static explicit operator StringHandle(Handle handle) 2351 { 2352 if ((handle.VType & ~(HandleType.VirtualBit | HandleType.NonVirtualStringTypeMask)) != HandleType.String) 2353 { 2354 Throw.InvalidCast(); 2355 } 2356 2357 // V111 10TT -> VTTx xxxx xxxx xxxx xxxx xxxx xxxx xxxx 2358 return new StringHandle( 2359 (handle.VType & HandleType.VirtualBit) << 24 | 2360 (handle.VType & HandleType.NonVirtualStringTypeMask) << HeapHandleType.OffsetBitCount | 2361 (uint)handle.Offset); 2362 } 2363 2364 internal uint RawValue => _value; 2365 2366 internal bool IsVirtual 2367 { 2368 get { return (_value & HeapHandleType.VirtualBit) != 0; } 2369 } 2370 2371 public bool IsNil 2372 { 2373 get 2374 { 2375 // virtual strings are never nil, so include virtual bit 2376 return (_value & (HeapHandleType.VirtualBit | HeapHandleType.OffsetMask)) == 0; 2377 } 2378 } 2379 GetHeapOffsetSystem.Reflection.Metadata.StringHandle2380 internal int GetHeapOffset() 2381 { 2382 // WinRT prefixed strings are virtual, the value is a heap offset 2383 Debug.Assert(!IsVirtual || StringKind == StringKind.WinRTPrefixed); 2384 return (int)(_value & HeapHandleType.OffsetMask); 2385 } 2386 GetVirtualIndexSystem.Reflection.Metadata.StringHandle2387 internal VirtualIndex GetVirtualIndex() 2388 { 2389 Debug.Assert(IsVirtual && StringKind != StringKind.WinRTPrefixed); 2390 return (VirtualIndex)(_value & HeapHandleType.OffsetMask); 2391 } 2392 GetWriterVirtualIndexSystem.Reflection.Metadata.StringHandle2393 internal int GetWriterVirtualIndex() 2394 { 2395 Debug.Assert(IsNil || IsVirtual && StringKind == StringKind.Virtual); 2396 return (int)(_value & HeapHandleType.OffsetMask); 2397 } 2398 2399 internal StringKind StringKind 2400 { 2401 get { return (StringKind)(_value >> HeapHandleType.OffsetBitCount); } 2402 } 2403 EqualsSystem.Reflection.Metadata.StringHandle2404 public override bool Equals(object obj) 2405 { 2406 return obj is StringHandle && Equals((StringHandle)obj); 2407 } 2408 EqualsSystem.Reflection.Metadata.StringHandle2409 public bool Equals(StringHandle other) 2410 { 2411 return _value == other._value; 2412 } 2413 GetHashCodeSystem.Reflection.Metadata.StringHandle2414 public override int GetHashCode() 2415 { 2416 return unchecked((int)_value); 2417 } 2418 operator ==System.Reflection.Metadata.StringHandle2419 public static bool operator ==(StringHandle left, StringHandle right) 2420 { 2421 return left.Equals(right); 2422 } 2423 operator !=System.Reflection.Metadata.StringHandle2424 public static bool operator !=(StringHandle left, StringHandle right) 2425 { 2426 return !left.Equals(right); 2427 } 2428 } 2429 2430 /// <summary> 2431 /// A handle that represents a namespace definition. 2432 /// </summary> 2433 public readonly struct NamespaceDefinitionHandle : IEquatable<NamespaceDefinitionHandle> 2434 { 2435 // Non-virtual (namespace having at least one type or forwarder of its own) 2436 // heap offset is to the null-terminated full name of the namespace in the 2437 // #String heap. 2438 // 2439 // Virtual (namespace having child namespaces but no types of its own) 2440 // the virtual index is an auto-incremented value and serves solely to 2441 // create unique values for indexing into the NamespaceCache. 2442 2443 // bits: 2444 // 31: IsVirtual 2445 // 29..31: 0 2446 // 0..28: Heap offset or Virtual index 2447 private readonly uint _value; 2448 NamespaceDefinitionHandleSystem.Reflection.Metadata.NamespaceDefinitionHandle2449 private NamespaceDefinitionHandle(uint value) 2450 { 2451 _value = value; 2452 } 2453 FromFullNameOffsetSystem.Reflection.Metadata.NamespaceDefinitionHandle2454 internal static NamespaceDefinitionHandle FromFullNameOffset(int stringHeapOffset) 2455 { 2456 return new NamespaceDefinitionHandle((uint)stringHeapOffset); 2457 } 2458 FromVirtualIndexSystem.Reflection.Metadata.NamespaceDefinitionHandle2459 internal static NamespaceDefinitionHandle FromVirtualIndex(uint virtualIndex) 2460 { 2461 // we arbitrarily disallow 0 virtual index to simplify nil check. 2462 Debug.Assert(virtualIndex != 0); 2463 2464 if (!HeapHandleType.IsValidHeapOffset(virtualIndex)) 2465 { 2466 // only a pathological assembly would hit this, but it must fit in 29 bits. 2467 Throw.TooManySubnamespaces(); 2468 } 2469 2470 return new NamespaceDefinitionHandle(TokenTypeIds.VirtualBit | virtualIndex); 2471 } 2472 operator HandleSystem.Reflection.Metadata.NamespaceDefinitionHandle2473 public static implicit operator Handle(NamespaceDefinitionHandle handle) 2474 { 2475 return new Handle( 2476 (byte)((handle._value & HeapHandleType.VirtualBit) >> 24 | HandleType.Namespace), 2477 (int)(handle._value & HeapHandleType.OffsetMask)); 2478 } 2479 operator NamespaceDefinitionHandleSystem.Reflection.Metadata.NamespaceDefinitionHandle2480 public static explicit operator NamespaceDefinitionHandle(Handle handle) 2481 { 2482 if ((handle.VType & HandleType.TypeMask) != HandleType.Namespace) 2483 { 2484 Throw.InvalidCast(); 2485 } 2486 2487 return new NamespaceDefinitionHandle( 2488 (handle.VType & HandleType.VirtualBit) << TokenTypeIds.RowIdBitCount | 2489 (uint)handle.Offset); 2490 } 2491 2492 public bool IsNil 2493 { 2494 get 2495 { 2496 return _value == 0; 2497 } 2498 } 2499 2500 internal bool IsVirtual 2501 { 2502 get { return (_value & HeapHandleType.VirtualBit) != 0; } 2503 } 2504 GetHeapOffsetSystem.Reflection.Metadata.NamespaceDefinitionHandle2505 internal int GetHeapOffset() 2506 { 2507 Debug.Assert(!IsVirtual); 2508 return (int)(_value & HeapHandleType.OffsetMask); 2509 } 2510 2511 internal bool HasFullName 2512 { 2513 get { return !IsVirtual; } 2514 } 2515 GetFullNameSystem.Reflection.Metadata.NamespaceDefinitionHandle2516 internal StringHandle GetFullName() 2517 { 2518 Debug.Assert(HasFullName); 2519 return StringHandle.FromOffset(GetHeapOffset()); 2520 } 2521 EqualsSystem.Reflection.Metadata.NamespaceDefinitionHandle2522 public override bool Equals(object obj) 2523 { 2524 return obj is NamespaceDefinitionHandle && Equals((NamespaceDefinitionHandle)obj); 2525 } 2526 EqualsSystem.Reflection.Metadata.NamespaceDefinitionHandle2527 public bool Equals(NamespaceDefinitionHandle other) 2528 { 2529 return _value == other._value; 2530 } 2531 GetHashCodeSystem.Reflection.Metadata.NamespaceDefinitionHandle2532 public override int GetHashCode() 2533 { 2534 return unchecked((int)_value); 2535 } 2536 operator ==System.Reflection.Metadata.NamespaceDefinitionHandle2537 public static bool operator ==(NamespaceDefinitionHandle left, NamespaceDefinitionHandle right) 2538 { 2539 return left.Equals(right); 2540 } 2541 operator !=System.Reflection.Metadata.NamespaceDefinitionHandle2542 public static bool operator !=(NamespaceDefinitionHandle left, NamespaceDefinitionHandle right) 2543 { 2544 return !left.Equals(right); 2545 } 2546 } 2547 2548 // #Blob heap handle 2549 public readonly struct BlobHandle : IEquatable<BlobHandle> 2550 { 2551 // bits: 2552 // 31: IsVirtual 2553 // 29..30: 0 2554 // 0..28: Heap offset or Virtual Value (16 bits) + Virtual Index (8 bits) 2555 private readonly uint _value; 2556 2557 internal enum VirtualIndex : byte 2558 { 2559 Nil, 2560 2561 // B0 3F 5F 7F 11 D5 0A 3A 2562 ContractPublicKeyToken, 2563 2564 // 00, 24, 00, 00, 04, ... 2565 ContractPublicKey, 2566 2567 // Template for projected AttributeUsage attribute blob 2568 AttributeUsage_AllowSingle, 2569 2570 // Template for projected AttributeUsage attribute blob with AllowMultiple=true 2571 AttributeUsage_AllowMultiple, 2572 2573 Count 2574 } 2575 BlobHandleSystem.Reflection.Metadata.BlobHandle2576 private BlobHandle(uint value) 2577 { 2578 _value = value; 2579 } 2580 FromOffsetSystem.Reflection.Metadata.BlobHandle2581 internal static BlobHandle FromOffset(int heapOffset) 2582 { 2583 return new BlobHandle((uint)heapOffset); 2584 } 2585 FromVirtualIndexSystem.Reflection.Metadata.BlobHandle2586 internal static BlobHandle FromVirtualIndex(VirtualIndex virtualIndex, ushort virtualValue) 2587 { 2588 Debug.Assert(virtualIndex < VirtualIndex.Count); 2589 return new BlobHandle(TokenTypeIds.VirtualBit | (uint)(virtualValue << 8) | (uint)virtualIndex); 2590 } 2591 2592 internal const int TemplateParameterOffset_AttributeUsageTarget = 2; 2593 SubstituteTemplateParametersSystem.Reflection.Metadata.BlobHandle2594 internal unsafe void SubstituteTemplateParameters(byte[] blob) 2595 { 2596 Debug.Assert(blob.Length >= TemplateParameterOffset_AttributeUsageTarget + 4); 2597 2598 fixed (byte* ptr = &blob[TemplateParameterOffset_AttributeUsageTarget]) 2599 { 2600 *((uint*)ptr) = VirtualValue; 2601 } 2602 } 2603 operator HandleSystem.Reflection.Metadata.BlobHandle2604 public static implicit operator Handle(BlobHandle handle) 2605 { 2606 // V... -> V111 0001 2607 return new Handle( 2608 (byte)((handle._value & HeapHandleType.VirtualBit) >> 24 | HandleType.Blob), 2609 (int)(handle._value & HeapHandleType.OffsetMask)); 2610 } 2611 operator BlobHandleSystem.Reflection.Metadata.BlobHandle2612 public static explicit operator BlobHandle(Handle handle) 2613 { 2614 if ((handle.VType & HandleType.TypeMask) != HandleType.Blob) 2615 { 2616 Throw.InvalidCast(); 2617 } 2618 2619 return new BlobHandle( 2620 (handle.VType & HandleType.VirtualBit) << TokenTypeIds.RowIdBitCount | 2621 (uint)handle.Offset); 2622 } 2623 2624 internal uint RawValue => _value; 2625 2626 public bool IsNil 2627 { 2628 get { return _value == 0; } 2629 } 2630 GetHeapOffsetSystem.Reflection.Metadata.BlobHandle2631 internal int GetHeapOffset() 2632 { 2633 Debug.Assert(!IsVirtual); 2634 return (int)_value; 2635 } 2636 GetVirtualIndexSystem.Reflection.Metadata.BlobHandle2637 internal VirtualIndex GetVirtualIndex() 2638 { 2639 Debug.Assert(IsVirtual); 2640 return (VirtualIndex)(_value & 0xff); 2641 } 2642 2643 internal bool IsVirtual 2644 { 2645 get { return (_value & TokenTypeIds.VirtualBit) != 0; } 2646 } 2647 2648 private ushort VirtualValue 2649 { 2650 get { return unchecked((ushort)(_value >> 8)); } 2651 } 2652 EqualsSystem.Reflection.Metadata.BlobHandle2653 public override bool Equals(object obj) 2654 { 2655 return obj is BlobHandle && Equals((BlobHandle)obj); 2656 } 2657 EqualsSystem.Reflection.Metadata.BlobHandle2658 public bool Equals(BlobHandle other) 2659 { 2660 return _value == other._value; 2661 } 2662 GetHashCodeSystem.Reflection.Metadata.BlobHandle2663 public override int GetHashCode() 2664 { 2665 return unchecked((int)_value); 2666 } 2667 operator ==System.Reflection.Metadata.BlobHandle2668 public static bool operator ==(BlobHandle left, BlobHandle right) 2669 { 2670 return left.Equals(right); 2671 } 2672 operator !=System.Reflection.Metadata.BlobHandle2673 public static bool operator !=(BlobHandle left, BlobHandle right) 2674 { 2675 return !left.Equals(right); 2676 } 2677 } 2678 2679 // #Guid heap handle 2680 public readonly struct GuidHandle : IEquatable<GuidHandle> 2681 { 2682 // The Guid heap is an array of GUIDs, each 16 bytes wide. 2683 // Its first element is numbered 1, its second 2, and so on. 2684 private readonly int _index; 2685 GuidHandleSystem.Reflection.Metadata.GuidHandle2686 private GuidHandle(int index) 2687 { 2688 _index = index; 2689 } 2690 FromIndexSystem.Reflection.Metadata.GuidHandle2691 internal static GuidHandle FromIndex(int heapIndex) 2692 { 2693 return new GuidHandle(heapIndex); 2694 } 2695 operator HandleSystem.Reflection.Metadata.GuidHandle2696 public static implicit operator Handle(GuidHandle handle) 2697 { 2698 return new Handle((byte)HandleType.Guid, handle._index); 2699 } 2700 operator GuidHandleSystem.Reflection.Metadata.GuidHandle2701 public static explicit operator GuidHandle(Handle handle) 2702 { 2703 if (handle.VType != HandleType.Guid) 2704 { 2705 Throw.InvalidCast(); 2706 } 2707 2708 return new GuidHandle(handle.Offset); 2709 } 2710 2711 public bool IsNil 2712 { 2713 get { return _index == 0; } 2714 } 2715 2716 internal int Index 2717 { 2718 get { return _index; } 2719 } 2720 EqualsSystem.Reflection.Metadata.GuidHandle2721 public override bool Equals(object obj) 2722 { 2723 return obj is GuidHandle && Equals((GuidHandle)obj); 2724 } 2725 EqualsSystem.Reflection.Metadata.GuidHandle2726 public bool Equals(GuidHandle other) 2727 { 2728 return _index == other._index; 2729 } 2730 GetHashCodeSystem.Reflection.Metadata.GuidHandle2731 public override int GetHashCode() 2732 { 2733 return _index; 2734 } 2735 operator ==System.Reflection.Metadata.GuidHandle2736 public static bool operator ==(GuidHandle left, GuidHandle right) 2737 { 2738 return left.Equals(right); 2739 } 2740 operator !=System.Reflection.Metadata.GuidHandle2741 public static bool operator !=(GuidHandle left, GuidHandle right) 2742 { 2743 return !left.Equals(right); 2744 } 2745 } 2746 } 2747