< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 34
Coverable lines: 34
Total lines: 1942
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/HandleCollections.TypeSystem.cs

#LineLine coverage
 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
 4using System.Collections;
 5using System.Collections.Generic;
 6using System.Collections.Immutable;
 7using System.Diagnostics;
 8using System.Reflection.Metadata.Ecma335;
 9
 10namespace System.Reflection.Metadata
 11{
 12    /// <summary>
 13    /// Represents generic type parameters of a method or type.
 14    /// </summary>
 15    public readonly struct GenericParameterHandleCollection : IReadOnlyList<GenericParameterHandle>
 16    {
 17        private readonly int _firstRowId;
 18        private readonly ushort _count;
 19
 20        internal GenericParameterHandleCollection(int firstRowId, ushort count)
 21        {
 22            _firstRowId = firstRowId;
 23            _count = count;
 24        }
 25
 26        public int Count
 27        {
 28            get
 29            {
 30                return _count;
 31            }
 32        }
 33
 34        public GenericParameterHandle this[int index]
 35        {
 36            get
 37            {
 38                if (index < 0 || index >= _count)
 39                {
 40                    Throw.IndexOutOfRange();
 41                }
 42
 43                return GenericParameterHandle.FromRowId(_firstRowId + index);
 44            }
 45        }
 46
 47        public Enumerator GetEnumerator()
 48        {
 49            return new Enumerator(_firstRowId, _firstRowId + _count - 1);
 50        }
 51
 52        IEnumerator<GenericParameterHandle> IEnumerable<GenericParameterHandle>.GetEnumerator()
 53        {
 54            return GetEnumerator();
 55        }
 56
 57        IEnumerator IEnumerable.GetEnumerator()
 58        {
 59            return GetEnumerator();
 60        }
 61
 62        public struct Enumerator : IEnumerator<GenericParameterHandle>, IEnumerator
 63        {
 64            private readonly int _lastRowId; // inclusive
 65
 66            // first parameter rid - 1: initial state
 67            // EnumEnded: enumeration ended
 68            private int _currentRowId;
 69
 70            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 71            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 72
 73            internal Enumerator(int firstRowId, int lastRowId)
 74            {
 75                _currentRowId = firstRowId - 1;
 76                _lastRowId = lastRowId;
 77            }
 78
 79            public GenericParameterHandle Current
 80            {
 81                get
 82                {
 83                    // PERF: keep this code small to enable inlining.
 84                    return GenericParameterHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 85                }
 86            }
 87
 88            public bool MoveNext()
 89            {
 90                // PERF: keep this code small to enable inlining.
 91
 92                if (_currentRowId >= _lastRowId)
 93                {
 94                    _currentRowId = EnumEnded;
 95                    return false;
 96                }
 97                else
 98                {
 99                    _currentRowId++;
 100                    return true;
 101                }
 102            }
 103
 104            object IEnumerator.Current
 105            {
 106                get { return Current; }
 107            }
 108
 109            void IEnumerator.Reset()
 110            {
 111                throw new NotSupportedException();
 112            }
 113
 114            void IDisposable.Dispose()
 115            {
 116            }
 117        }
 118    }
 119
 120    /// <summary>
 121    /// Represents constraints of a generic type parameter.
 122    /// </summary>
 123    public readonly struct GenericParameterConstraintHandleCollection : IReadOnlyList<GenericParameterConstraintHandle>
 124    {
 125        private readonly int _firstRowId;
 126        private readonly ushort _count;
 127
 128        internal GenericParameterConstraintHandleCollection(int firstRowId, ushort count)
 129        {
 130            _firstRowId = firstRowId;
 131            _count = count;
 132        }
 133
 134        public int Count
 135        {
 136            get
 137            {
 138                return _count;
 139            }
 140        }
 141
 142        public GenericParameterConstraintHandle this[int index]
 143        {
 144            get
 145            {
 146                if (index < 0 || index >= _count)
 147                {
 148                    Throw.IndexOutOfRange();
 149                }
 150
 151                return GenericParameterConstraintHandle.FromRowId(_firstRowId + index);
 152            }
 153        }
 154
 155        public Enumerator GetEnumerator()
 156        {
 157            return new Enumerator(_firstRowId, _firstRowId + _count - 1);
 158        }
 159
 160        IEnumerator<GenericParameterConstraintHandle> IEnumerable<GenericParameterConstraintHandle>.GetEnumerator()
 161        {
 162            return GetEnumerator();
 163        }
 164
 165        IEnumerator IEnumerable.GetEnumerator()
 166        {
 167            return GetEnumerator();
 168        }
 169
 170        public struct Enumerator : IEnumerator<GenericParameterConstraintHandle>, IEnumerator
 171        {
 172            private readonly int _lastRowId; // inclusive
 173
 174            // first parameter rid - 1: initial state
 175            // EnumEnded: enumeration ended
 176            private int _currentRowId;
 177
 178            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 179            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 180
 181            internal Enumerator(int firstRowId, int lastRowId)
 182            {
 183                _currentRowId = firstRowId - 1;
 184                _lastRowId = lastRowId;
 185            }
 186
 187            public GenericParameterConstraintHandle Current
 188            {
 189                get
 190                {
 191                    // PERF: keep this code small to enable inlining.
 192                    return GenericParameterConstraintHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 193                }
 194            }
 195
 196            public bool MoveNext()
 197            {
 198                // PERF: keep this code small to enable inlining.
 199
 200                if (_currentRowId >= _lastRowId)
 201                {
 202                    _currentRowId = EnumEnded;
 203                    return false;
 204                }
 205                else
 206                {
 207                    _currentRowId++;
 208                    return true;
 209                }
 210            }
 211
 212            object IEnumerator.Current
 213            {
 214                get { return Current; }
 215            }
 216
 217            void IEnumerator.Reset()
 218            {
 219                throw new NotSupportedException();
 220            }
 221
 222            void IDisposable.Dispose()
 223            {
 224            }
 225        }
 226    }
 227
 228    public readonly struct CustomAttributeHandleCollection : IReadOnlyCollection<CustomAttributeHandle>
 229    {
 230        private readonly MetadataReader _reader;
 231
 232        private readonly int _firstRowId;
 233        private readonly int _lastRowId;
 234
 235        internal CustomAttributeHandleCollection(MetadataReader reader)
 236        {
 237            Debug.Assert(reader != null);
 238            _reader = reader;
 239            _firstRowId = 1;
 240            _lastRowId = reader.CustomAttributeTable.NumberOfRows;
 241        }
 242
 243        internal CustomAttributeHandleCollection(MetadataReader reader, EntityHandle handle)
 244        {
 245            Debug.Assert(reader != null);
 246
 247            _reader = reader;
 248            reader.CustomAttributeTable.GetAttributeRange(handle, out _firstRowId, out _lastRowId);
 249        }
 250
 251        public int Count
 252        {
 253            get
 254            {
 255                return _lastRowId - _firstRowId + 1;
 256            }
 257        }
 258
 259        public Enumerator GetEnumerator()
 260        {
 261            return new Enumerator(_reader, _firstRowId, _lastRowId);
 262        }
 263
 264        IEnumerator<CustomAttributeHandle> IEnumerable<CustomAttributeHandle>.GetEnumerator()
 265        {
 266            return GetEnumerator();
 267        }
 268
 269        IEnumerator IEnumerable.GetEnumerator()
 270        {
 271            return GetEnumerator();
 272        }
 273
 274        public struct Enumerator : IEnumerator<CustomAttributeHandle>, IEnumerator
 275        {
 276            private readonly MetadataReader _reader;
 277            private readonly int _lastRowId; // inclusive
 278
 279            // first custom attribute rid - 1: initial state
 280            // EnumEnded: enumeration ended
 281            private int _currentRowId;
 282
 283            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 284            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 285
 286            internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId)
 287            {
 288                _reader = reader;
 289                _currentRowId = firstRowId - 1;
 290                _lastRowId = lastRowId;
 291            }
 292
 293            public CustomAttributeHandle Current
 294            {
 295                get
 296                {
 297                    // PERF: keep this code small to enable inlining.
 298
 299                    if (_reader.CustomAttributeTable.PtrTable != null)
 300                    {
 301                        return GetCurrentCustomAttributeIndirect();
 302                    }
 303                    else
 304                    {
 305                        return CustomAttributeHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 306                    }
 307                }
 308            }
 309
 310            private CustomAttributeHandle GetCurrentCustomAttributeIndirect()
 311            {
 312                return CustomAttributeHandle.FromRowId(
 313                    _reader.CustomAttributeTable.PtrTable![(_currentRowId & (int)TokenTypeIds.RIDMask) - 1]);
 314            }
 315
 316            public bool MoveNext()
 317            {
 318                // PERF: keep this code small to enable inlining.
 319
 320                if (_currentRowId >= _lastRowId)
 321                {
 322                    _currentRowId = EnumEnded;
 323                    return false;
 324                }
 325                else
 326                {
 327                    _currentRowId++;
 328                    return true;
 329                }
 330            }
 331
 332            object IEnumerator.Current
 333            {
 334                get { return Current; }
 335            }
 336
 337            void IEnumerator.Reset()
 338            {
 339                throw new NotSupportedException();
 340            }
 341
 342            void IDisposable.Dispose()
 343            {
 344            }
 345        }
 346    }
 347
 348    public readonly struct DeclarativeSecurityAttributeHandleCollection : IReadOnlyCollection<DeclarativeSecurityAttribu
 349    {
 350        private readonly MetadataReader _reader;
 351
 352        private readonly int _firstRowId;
 353        private readonly int _lastRowId;
 354
 355        internal DeclarativeSecurityAttributeHandleCollection(MetadataReader reader)
 356        {
 357            Debug.Assert(reader != null);
 358            _reader = reader;
 359            _firstRowId = 1;
 360            _lastRowId = reader.DeclSecurityTable.NumberOfRows;
 361        }
 362
 363        internal DeclarativeSecurityAttributeHandleCollection(MetadataReader reader, EntityHandle handle)
 364        {
 365            Debug.Assert(reader != null);
 366            Debug.Assert(!handle.IsNil);
 367
 368            _reader = reader;
 369            reader.DeclSecurityTable.GetAttributeRange(handle, out _firstRowId, out _lastRowId);
 370        }
 371
 372        public int Count
 373        {
 374            get
 375            {
 376                return _lastRowId - _firstRowId + 1;
 377            }
 378        }
 379
 380        public Enumerator GetEnumerator()
 381        {
 382            return new Enumerator(_reader, _firstRowId, _lastRowId);
 383        }
 384
 385        IEnumerator<DeclarativeSecurityAttributeHandle> IEnumerable<DeclarativeSecurityAttributeHandle>.GetEnumerator()
 386        {
 387            return GetEnumerator();
 388        }
 389
 390        IEnumerator IEnumerable.GetEnumerator()
 391        {
 392            return GetEnumerator();
 393        }
 394
 395        public struct Enumerator : IEnumerator<DeclarativeSecurityAttributeHandle>, IEnumerator
 396        {
 397            private readonly MetadataReader _reader;
 398            private readonly int _lastRowId; // inclusive
 399
 400            // first custom attribute rid - 1: initial state
 401            // EnumEnded: enumeration ended
 402            private int _currentRowId;
 403
 404            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 405            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 406
 407            internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId)
 408            {
 409                _reader = reader;
 410                _currentRowId = firstRowId - 1;
 411                _lastRowId = lastRowId;
 412            }
 413
 414            public DeclarativeSecurityAttributeHandle Current
 415            {
 416                get
 417                {
 418                    // PERF: keep this code small to enable inlining.
 419                    return DeclarativeSecurityAttributeHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 420                }
 421            }
 422
 423            public bool MoveNext()
 424            {
 425                // PERF: keep this code small to enable inlining.
 426
 427                if (_currentRowId >= _lastRowId)
 428                {
 429                    _currentRowId = EnumEnded;
 430                    return false;
 431                }
 432                else
 433                {
 434                    _currentRowId++;
 435                    return true;
 436                }
 437            }
 438
 439            object IEnumerator.Current
 440            {
 441                get { return Current; }
 442            }
 443
 444            void IEnumerator.Reset()
 445            {
 446                throw new NotSupportedException();
 447            }
 448
 449            void IDisposable.Dispose()
 450            {
 451            }
 452        }
 453    }
 454
 455    public readonly struct MethodDefinitionHandleCollection : IReadOnlyCollection<MethodDefinitionHandle>
 456    {
 457        private readonly MetadataReader _reader;
 458
 459        private readonly int _firstRowId;
 460        private readonly int _lastRowId;
 461
 462        internal MethodDefinitionHandleCollection(MetadataReader reader)
 463        {
 464            Debug.Assert(reader != null);
 465            _reader = reader;
 466            _firstRowId = 1;
 467            _lastRowId = reader.MethodDefTable.NumberOfRows;
 468        }
 469
 470        internal MethodDefinitionHandleCollection(MetadataReader reader, TypeDefinitionHandle containingType)
 471        {
 472            Debug.Assert(reader != null);
 473            Debug.Assert(!containingType.IsNil);
 474
 475            _reader = reader;
 476            reader.GetMethodRange(containingType, out _firstRowId, out _lastRowId);
 477        }
 478
 479        public int Count
 480        {
 481            get
 482            {
 483                return _lastRowId - _firstRowId + 1;
 484            }
 485        }
 486
 487        public Enumerator GetEnumerator()
 488        {
 489            return new Enumerator(_reader, _firstRowId, _lastRowId);
 490        }
 491
 492        IEnumerator<MethodDefinitionHandle> IEnumerable<MethodDefinitionHandle>.GetEnumerator()
 493        {
 494            return GetEnumerator();
 495        }
 496
 497        IEnumerator IEnumerable.GetEnumerator()
 498        {
 499            return GetEnumerator();
 500        }
 501
 502        public struct Enumerator : IEnumerator<MethodDefinitionHandle>, IEnumerator
 503        {
 504            private readonly MetadataReader _reader;
 505            private readonly int _lastRowId; // inclusive
 506
 507            // first method rid - 1: initial state
 508            // EnumEnded: enumeration ended
 509            private int _currentRowId;
 510
 511            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 512            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 513
 514            internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId)
 515            {
 516                _reader = reader;
 517                _currentRowId = firstRowId - 1;
 518                _lastRowId = lastRowId;
 519            }
 520
 521            public MethodDefinitionHandle Current
 522            {
 523                get
 524                {
 525                    // PERF: keep this code small to enable inlining.
 526
 527                    if (_reader.UseMethodPtrTable)
 528                    {
 529                        return GetCurrentMethodIndirect();
 530                    }
 531                    else
 532                    {
 533                        return MethodDefinitionHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 534                    }
 535                }
 536            }
 537
 538            private MethodDefinitionHandle GetCurrentMethodIndirect()
 539            {
 540                return _reader.MethodPtrTable.GetMethodFor(_currentRowId & (int)TokenTypeIds.RIDMask);
 541            }
 542
 543            public bool MoveNext()
 544            {
 545                // PERF: keep this code small to enable inlining.
 546
 547                if (_currentRowId >= _lastRowId)
 548                {
 549                    _currentRowId = EnumEnded;
 550                    return false;
 551                }
 552                else
 553                {
 554                    _currentRowId++;
 555                    return true;
 556                }
 557            }
 558
 559            object IEnumerator.Current
 560            {
 561                get { return Current; }
 562            }
 563
 564            void IEnumerator.Reset()
 565            {
 566                throw new NotSupportedException();
 567            }
 568
 569            void IDisposable.Dispose()
 570            {
 571            }
 572        }
 573    }
 574
 575    public readonly struct FieldDefinitionHandleCollection : IReadOnlyCollection<FieldDefinitionHandle>
 576    {
 577        private readonly MetadataReader _reader;
 578
 579        private readonly int _firstRowId;
 580        private readonly int _lastRowId;
 581
 582        internal FieldDefinitionHandleCollection(MetadataReader reader)
 583        {
 584            Debug.Assert(reader != null);
 585            _reader = reader;
 586            _firstRowId = 1;
 587            _lastRowId = reader.FieldTable.NumberOfRows;
 588        }
 589
 590        internal FieldDefinitionHandleCollection(MetadataReader reader, TypeDefinitionHandle containingType)
 591        {
 592            Debug.Assert(reader != null);
 593            Debug.Assert(!containingType.IsNil);
 594
 595            _reader = reader;
 596            reader.GetFieldRange(containingType, out _firstRowId, out _lastRowId);
 597        }
 598
 599        public int Count
 600        {
 601            get
 602            {
 603                return _lastRowId - _firstRowId + 1;
 604            }
 605        }
 606
 607        public Enumerator GetEnumerator()
 608        {
 609            return new Enumerator(_reader, _firstRowId, _lastRowId);
 610        }
 611
 612        IEnumerator<FieldDefinitionHandle> IEnumerable<FieldDefinitionHandle>.GetEnumerator()
 613        {
 614            return GetEnumerator();
 615        }
 616
 617        IEnumerator IEnumerable.GetEnumerator()
 618        {
 619            return GetEnumerator();
 620        }
 621
 622        public struct Enumerator : IEnumerator<FieldDefinitionHandle>, IEnumerator
 623        {
 624            private readonly MetadataReader _reader;
 625            private readonly int _lastRowId; // inclusive
 626
 627            // first field rid - 1: initial state
 628            // EnumEnded: enumeration ended
 629            private int _currentRowId;
 630
 631            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 632            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 633
 634            internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId)
 635            {
 636                _reader = reader;
 637                _currentRowId = firstRowId - 1;
 638                _lastRowId = lastRowId;
 639            }
 640
 641            public FieldDefinitionHandle Current
 642            {
 643                get
 644                {
 645                    // PERF: keep this code small to enable inlining.
 646
 647                    if (_reader.UseFieldPtrTable)
 648                    {
 649                        return GetCurrentFieldIndirect();
 650                    }
 651                    else
 652                    {
 653                        return FieldDefinitionHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 654                    }
 655                }
 656            }
 657
 658            private FieldDefinitionHandle GetCurrentFieldIndirect()
 659            {
 660                return _reader.FieldPtrTable.GetFieldFor(_currentRowId & (int)TokenTypeIds.RIDMask);
 661            }
 662
 663            public bool MoveNext()
 664            {
 665                // PERF: keep this code small to enable inlining.
 666
 667                if (_currentRowId >= _lastRowId)
 668                {
 669                    _currentRowId = EnumEnded;
 670                    return false;
 671                }
 672                else
 673                {
 674                    _currentRowId++;
 675                    return true;
 676                }
 677            }
 678
 679            object IEnumerator.Current
 680            {
 681                get { return Current; }
 682            }
 683
 684            void IEnumerator.Reset()
 685            {
 686                throw new NotSupportedException();
 687            }
 688
 689            void IDisposable.Dispose()
 690            {
 691            }
 692        }
 693    }
 694
 695    public readonly struct PropertyDefinitionHandleCollection : IReadOnlyCollection<PropertyDefinitionHandle>
 696    {
 697        private readonly MetadataReader _reader;
 698
 699        private readonly int _firstRowId;
 700        private readonly int _lastRowId;
 701
 702        internal PropertyDefinitionHandleCollection(MetadataReader reader)
 703        {
 704            Debug.Assert(reader != null);
 705            _reader = reader;
 706            _firstRowId = 1;
 707            _lastRowId = reader.PropertyTable.NumberOfRows;
 708        }
 709
 710        internal PropertyDefinitionHandleCollection(MetadataReader reader, TypeDefinitionHandle containingType)
 711        {
 712            Debug.Assert(reader != null);
 713            Debug.Assert(!containingType.IsNil);
 714
 715            _reader = reader;
 716            reader.GetPropertyRange(containingType, out _firstRowId, out _lastRowId);
 717        }
 718
 719        public int Count
 720        {
 721            get
 722            {
 723                return _lastRowId - _firstRowId + 1;
 724            }
 725        }
 726
 727        public Enumerator GetEnumerator()
 728        {
 729            return new Enumerator(_reader, _firstRowId, _lastRowId);
 730        }
 731
 732        IEnumerator<PropertyDefinitionHandle> IEnumerable<PropertyDefinitionHandle>.GetEnumerator()
 733        {
 734            return GetEnumerator();
 735        }
 736
 737        IEnumerator IEnumerable.GetEnumerator()
 738        {
 739            return GetEnumerator();
 740        }
 741
 742        public struct Enumerator : IEnumerator<PropertyDefinitionHandle>, IEnumerator
 743        {
 744            private readonly MetadataReader _reader;
 745            private readonly int _lastRowId; // inclusive
 746
 747            // first Property rid - 1: initial state
 748            // EnumEnded: enumeration ended
 749            private int _currentRowId;
 750
 751            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 752            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 753
 754            internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId)
 755            {
 756                _reader = reader;
 757                _currentRowId = firstRowId - 1;
 758                _lastRowId = lastRowId;
 759            }
 760
 761            public PropertyDefinitionHandle Current
 762            {
 763                get
 764                {
 765                    // PERF: keep this code small to enable inlining.
 766
 767                    if (_reader.UsePropertyPtrTable)
 768                    {
 769                        return GetCurrentPropertyIndirect();
 770                    }
 771                    else
 772                    {
 773                        return PropertyDefinitionHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 774                    }
 775                }
 776            }
 777
 778            private PropertyDefinitionHandle GetCurrentPropertyIndirect()
 779            {
 780                return _reader.PropertyPtrTable.GetPropertyFor(_currentRowId & (int)TokenTypeIds.RIDMask);
 781            }
 782
 783            public bool MoveNext()
 784            {
 785                // PERF: keep this code small to enable inlining.
 786
 787                if (_currentRowId >= _lastRowId)
 788                {
 789                    _currentRowId = EnumEnded;
 790                    return false;
 791                }
 792                else
 793                {
 794                    _currentRowId++;
 795                    return true;
 796                }
 797            }
 798
 799            object IEnumerator.Current
 800            {
 801                get { return Current; }
 802            }
 803
 804            void IEnumerator.Reset()
 805            {
 806                throw new NotSupportedException();
 807            }
 808
 809            void IDisposable.Dispose()
 810            {
 811            }
 812        }
 813    }
 814
 815    public readonly struct EventDefinitionHandleCollection : IReadOnlyCollection<EventDefinitionHandle>
 816    {
 817        private readonly MetadataReader _reader;
 818
 819        private readonly int _firstRowId;
 820        private readonly int _lastRowId;
 821
 822        internal EventDefinitionHandleCollection(MetadataReader reader)
 823        {
 824            Debug.Assert(reader != null);
 825            _reader = reader;
 826            _firstRowId = 1;
 827            _lastRowId = reader.EventTable.NumberOfRows;
 828        }
 829
 830        internal EventDefinitionHandleCollection(MetadataReader reader, TypeDefinitionHandle containingType)
 831        {
 832            Debug.Assert(reader != null);
 833            Debug.Assert(!containingType.IsNil);
 834
 835            _reader = reader;
 836            reader.GetEventRange(containingType, out _firstRowId, out _lastRowId);
 837        }
 838
 839        public int Count
 840        {
 841            get
 842            {
 843                return _lastRowId - _firstRowId + 1;
 844            }
 845        }
 846
 847        public Enumerator GetEnumerator()
 848        {
 849            return new Enumerator(_reader, _firstRowId, _lastRowId);
 850        }
 851
 852        IEnumerator<EventDefinitionHandle> IEnumerable<EventDefinitionHandle>.GetEnumerator()
 853        {
 854            return GetEnumerator();
 855        }
 856
 857        IEnumerator IEnumerable.GetEnumerator()
 858        {
 859            return GetEnumerator();
 860        }
 861
 862        public struct Enumerator : IEnumerator<EventDefinitionHandle>, IEnumerator
 863        {
 864            private readonly MetadataReader _reader;
 865            private readonly int _lastRowId;
 866
 867            // first rid - 1: initial state
 868            // EnumEnded: enumeration ended
 869            private int _currentRowId;
 870
 871            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 872            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 873
 874            internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId)
 875            {
 876                _reader = reader;
 877                _currentRowId = firstRowId - 1;
 878                _lastRowId = lastRowId;
 879            }
 880
 881            public EventDefinitionHandle Current
 882            {
 883                get
 884                {
 885                    // PERF: keep this code small to enable inlining.
 886
 887                    if (_reader.UseEventPtrTable)
 888                    {
 889                        return GetCurrentEventIndirect();
 890                    }
 891                    else
 892                    {
 893                        return EventDefinitionHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 894                    }
 895                }
 896            }
 897
 898            private EventDefinitionHandle GetCurrentEventIndirect()
 899            {
 900                return _reader.EventPtrTable.GetEventFor(_currentRowId & (int)TokenTypeIds.RIDMask);
 901            }
 902
 903            public bool MoveNext()
 904            {
 905                // PERF: keep this code small to enable inlining.
 906
 907                if (_currentRowId >= _lastRowId)
 908                {
 909                    _currentRowId = EnumEnded;
 910                    return false;
 911                }
 912                else
 913                {
 914                    _currentRowId++;
 915                    return true;
 916                }
 917            }
 918
 919            object IEnumerator.Current
 920            {
 921                get { return Current; }
 922            }
 923
 924            void IEnumerator.Reset()
 925            {
 926                throw new NotSupportedException();
 927            }
 928
 929            void IDisposable.Dispose()
 930            {
 931            }
 932        }
 933    }
 934
 935    public readonly struct MethodImplementationHandleCollection : IReadOnlyCollection<MethodImplementationHandle>
 936    {
 937        private readonly int _firstRowId;
 938        private readonly int _lastRowId;
 939
 940        internal MethodImplementationHandleCollection(MetadataReader reader, TypeDefinitionHandle containingType)
 941        {
 942            Debug.Assert(reader != null);
 943
 944            if (containingType.IsNil)
 945            {
 946                _firstRowId = 1;
 947                _lastRowId = reader.MethodImplTable.NumberOfRows;
 948            }
 949            else
 950            {
 951                reader.MethodImplTable.GetMethodImplRange(containingType, out _firstRowId, out _lastRowId);
 952            }
 953        }
 954
 955        public int Count
 956        {
 957            get
 958            {
 959                return _lastRowId - _firstRowId + 1;
 960            }
 961        }
 962
 963        public Enumerator GetEnumerator()
 964        {
 965            return new Enumerator(_firstRowId, _lastRowId);
 966        }
 967
 968        IEnumerator<MethodImplementationHandle> IEnumerable<MethodImplementationHandle>.GetEnumerator()
 969        {
 970            return GetEnumerator();
 971        }
 972
 973        IEnumerator IEnumerable.GetEnumerator()
 974        {
 975            return GetEnumerator();
 976        }
 977
 978        public struct Enumerator : IEnumerator<MethodImplementationHandle>, IEnumerator
 979        {
 980            private readonly int _lastRowId; // inclusive
 981
 982            // first impl rid - 1: initial state
 983            // EnumEnded: enumeration ended
 984            private int _currentRowId;
 985
 986            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 987            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 988
 989            internal Enumerator(int firstRowId, int lastRowId)
 990            {
 991                _currentRowId = firstRowId - 1;
 992                _lastRowId = lastRowId;
 993            }
 994
 995            public MethodImplementationHandle Current
 996            {
 997                get
 998                {
 999                    return MethodImplementationHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 1000                }
 1001            }
 1002
 1003            public bool MoveNext()
 1004            {
 1005                // PERF: keep this code small to enable inlining.
 1006
 1007                if (_currentRowId >= _lastRowId)
 1008                {
 1009                    _currentRowId = EnumEnded;
 1010                    return false;
 1011                }
 1012                else
 1013                {
 1014                    _currentRowId++;
 1015                    return true;
 1016                }
 1017            }
 1018
 1019            object IEnumerator.Current
 1020            {
 1021                get { return Current; }
 1022            }
 1023
 1024            void IEnumerator.Reset()
 1025            {
 1026                throw new NotSupportedException();
 1027            }
 1028
 1029            void IDisposable.Dispose()
 1030            {
 1031            }
 1032        }
 1033    }
 1034
 1035    /// <summary>
 1036    /// Collection of parameters of a specified method.
 1037    /// </summary>
 1038    public readonly struct ParameterHandleCollection : IReadOnlyCollection<ParameterHandle>
 1039    {
 1040        private readonly MetadataReader _reader;
 1041
 1042        private readonly int _firstRowId;
 1043        private readonly int _lastRowId;
 1044
 1045        internal ParameterHandleCollection(MetadataReader reader, MethodDefinitionHandle containingMethod)
 1046        {
 1047            Debug.Assert(reader != null);
 1048            Debug.Assert(!containingMethod.IsNil);
 1049            _reader = reader;
 1050
 1051            reader.GetParameterRange(containingMethod, out _firstRowId, out _lastRowId);
 1052        }
 1053
 1054        public int Count
 1055        {
 1056            get
 1057            {
 1058                return _lastRowId - _firstRowId + 1;
 1059            }
 1060        }
 1061
 1062        public Enumerator GetEnumerator()
 1063        {
 1064            return new Enumerator(_reader, _firstRowId, _lastRowId);
 1065        }
 1066
 1067        IEnumerator<ParameterHandle> IEnumerable<ParameterHandle>.GetEnumerator()
 1068        {
 1069            return GetEnumerator();
 1070        }
 1071
 1072        IEnumerator IEnumerable.GetEnumerator()
 1073        {
 1074            return GetEnumerator();
 1075        }
 1076
 1077        public struct Enumerator : IEnumerator<ParameterHandle>, IEnumerator
 1078        {
 1079            private readonly MetadataReader _reader;
 1080            private readonly int _lastRowId; // inclusive
 1081
 1082            // first Parameter rid - 1: initial state
 1083            // EnumEnded: enumeration ended
 1084            private int _currentRowId;
 1085
 1086            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 1087            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 1088
 1089            internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId)
 1090            {
 1091                _reader = reader;
 1092                _lastRowId = lastRowId;
 1093                _currentRowId = firstRowId - 1;
 1094            }
 1095
 1096            public ParameterHandle Current
 1097            {
 1098                get
 1099                {
 1100                    // PERF: keep this code small to enable inlining.
 1101
 1102                    if (_reader.UseParamPtrTable)
 1103                    {
 1104                        return GetCurrentParameterIndirect();
 1105                    }
 1106                    else
 1107                    {
 1108                        return ParameterHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 1109                    }
 1110                }
 1111            }
 1112
 1113            private ParameterHandle GetCurrentParameterIndirect()
 1114            {
 1115                return _reader.ParamPtrTable.GetParamFor(_currentRowId & (int)TokenTypeIds.RIDMask);
 1116            }
 1117
 1118            public bool MoveNext()
 1119            {
 1120                // PERF: keep this code small to enable inlining.
 1121
 1122                if (_currentRowId >= _lastRowId)
 1123                {
 1124                    _currentRowId = EnumEnded;
 1125                    return false;
 1126                }
 1127                else
 1128                {
 1129                    _currentRowId++;
 1130                    return true;
 1131                }
 1132            }
 1133
 1134            object IEnumerator.Current
 1135            {
 1136                get { return Current; }
 1137            }
 1138
 1139            void IEnumerator.Reset()
 1140            {
 1141                throw new NotSupportedException();
 1142            }
 1143
 1144            void IDisposable.Dispose()
 1145            {
 1146            }
 1147        }
 1148    }
 1149
 1150    public readonly struct InterfaceImplementationHandleCollection : IReadOnlyCollection<InterfaceImplementationHandle>
 1151    {
 1152        private readonly MetadataReader _reader;
 1153
 1154        private readonly int _firstRowId;
 1155        private readonly int _lastRowId;
 1156
 1157        internal InterfaceImplementationHandleCollection(MetadataReader reader, TypeDefinitionHandle implementingType)
 1158        {
 1159            Debug.Assert(reader != null);
 1160            Debug.Assert(!implementingType.IsNil);
 1161            _reader = reader;
 1162
 1163            reader.InterfaceImplTable.GetInterfaceImplRange(implementingType, out _firstRowId, out _lastRowId);
 1164        }
 1165
 1166        public int Count
 1167        {
 1168            get
 1169            {
 1170                return _lastRowId - _firstRowId + 1;
 1171            }
 1172        }
 1173
 1174        public Enumerator GetEnumerator()
 1175        {
 1176            return new Enumerator(_reader, _firstRowId, _lastRowId);
 1177        }
 1178
 1179        IEnumerator<InterfaceImplementationHandle> IEnumerable<InterfaceImplementationHandle>.GetEnumerator()
 1180        {
 1181            return GetEnumerator();
 1182        }
 1183
 1184        IEnumerator IEnumerable.GetEnumerator()
 1185        {
 1186            return GetEnumerator();
 1187        }
 1188
 1189        public struct Enumerator : IEnumerator<InterfaceImplementationHandle>, IEnumerator
 1190        {
 1191            private readonly MetadataReader _reader;
 1192            private readonly int _lastRowId; // inclusive
 1193
 1194            // first rid - 1: initial state
 1195            // EnumEnded: enumeration ended
 1196            private int _currentRowId;
 1197
 1198            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 1199            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 1200
 1201            internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId)
 1202            {
 1203                _reader = reader;
 1204                _currentRowId = firstRowId - 1;
 1205                _lastRowId = lastRowId;
 1206            }
 1207
 1208            public InterfaceImplementationHandle Current
 1209            {
 1210                get
 1211                {
 1212                    return InterfaceImplementationHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 1213                }
 1214            }
 1215
 1216            public bool MoveNext()
 1217            {
 1218                // PERF: keep this code small to enable inlining.
 1219
 1220                if (_currentRowId >= _lastRowId)
 1221                {
 1222                    _currentRowId = EnumEnded;
 1223                    return false;
 1224                }
 1225                else
 1226                {
 1227                    _currentRowId++;
 1228                    return true;
 1229                }
 1230            }
 1231
 1232            object IEnumerator.Current
 1233            {
 1234                get { return Current; }
 1235            }
 1236
 1237            void IEnumerator.Reset()
 1238            {
 1239                throw new NotSupportedException();
 1240            }
 1241
 1242            void IDisposable.Dispose()
 1243            {
 1244            }
 1245        }
 1246    }
 1247
 1248    /// <summary>
 1249    /// Represents a collection of <see cref="TypeDefinitionHandle"/>.
 1250    /// </summary>
 1251    public readonly struct TypeDefinitionHandleCollection : IReadOnlyCollection<TypeDefinitionHandle>
 1252    {
 1253        private readonly int _lastRowId;
 1254
 1255        // Creates collection that represents the entire TypeDef table.
 1256        internal TypeDefinitionHandleCollection(int lastRowId)
 1257        {
 1258            _lastRowId = lastRowId;
 1259        }
 1260
 1261        public int Count
 1262        {
 1263            get { return _lastRowId; }
 1264        }
 1265
 1266        public Enumerator GetEnumerator()
 1267        {
 1268            return new Enumerator(_lastRowId);
 1269        }
 1270
 1271        IEnumerator<TypeDefinitionHandle> IEnumerable<TypeDefinitionHandle>.GetEnumerator()
 1272        {
 1273            return GetEnumerator();
 1274        }
 1275
 1276        IEnumerator IEnumerable.GetEnumerator()
 1277        {
 1278            return GetEnumerator();
 1279        }
 1280
 1281        public struct Enumerator : IEnumerator<TypeDefinitionHandle>, IEnumerator
 1282        {
 1283            private readonly int _lastRowId;
 1284
 1285            // 0: initial state
 1286            // EnumEnded: enumeration ended
 1287            private int _currentRowId;
 1288
 1289            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 1290            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 1291
 1292            internal Enumerator(int lastRowId)
 1293            {
 1294                _lastRowId = lastRowId;
 1295                _currentRowId = 0;
 1296            }
 1297
 1298            public TypeDefinitionHandle Current
 1299            {
 1300                get
 1301                {
 1302                    return TypeDefinitionHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 1303                }
 1304            }
 1305
 1306            public bool MoveNext()
 1307            {
 1308                // PERF: keep this method small to enable inlining.
 1309
 1310                if (_currentRowId >= _lastRowId)
 1311                {
 1312                    _currentRowId = EnumEnded;
 1313                    return false;
 1314                }
 1315                else
 1316                {
 1317                    _currentRowId++;
 1318                    return true;
 1319                }
 1320            }
 1321
 1322            object IEnumerator.Current
 1323            {
 1324                get { return Current; }
 1325            }
 1326
 1327            void IEnumerator.Reset()
 1328            {
 1329                throw new NotSupportedException();
 1330            }
 1331
 1332            void IDisposable.Dispose()
 1333            {
 1334            }
 1335        }
 1336    }
 1337
 1338    /// <summary>
 1339    /// Represents a collection of <see cref="TypeReferenceHandle"/>.
 1340    /// </summary>
 1341    public readonly struct TypeReferenceHandleCollection : IReadOnlyCollection<TypeReferenceHandle>
 1342    {
 1343        private readonly int _lastRowId;
 1344
 1345        // Creates collection that represents the entire TypeRef table.
 1346        internal TypeReferenceHandleCollection(int lastRowId)
 1347        {
 1348            _lastRowId = lastRowId;
 1349        }
 1350
 1351        public int Count
 1352        {
 1353            get { return _lastRowId; }
 1354        }
 1355
 1356        public Enumerator GetEnumerator()
 1357        {
 1358            return new Enumerator(_lastRowId);
 1359        }
 1360
 1361        IEnumerator<TypeReferenceHandle> IEnumerable<TypeReferenceHandle>.GetEnumerator()
 1362        {
 1363            return GetEnumerator();
 1364        }
 1365
 1366        IEnumerator IEnumerable.GetEnumerator()
 1367        {
 1368            return GetEnumerator();
 1369        }
 1370
 1371        public struct Enumerator : IEnumerator<TypeReferenceHandle>, IEnumerator
 1372        {
 1373            private readonly int _lastRowId;
 1374
 1375            // 0: initial state
 1376            // EnumEnded: enumeration ended
 1377            private int _currentRowId;
 1378
 1379            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 1380            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 1381
 1382            internal Enumerator(int lastRowId)
 1383            {
 1384                _lastRowId = lastRowId;
 1385                _currentRowId = 0;
 1386            }
 1387
 1388            public TypeReferenceHandle Current
 1389            {
 1390                get
 1391                {
 1392                    return TypeReferenceHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 1393                }
 1394            }
 1395
 1396            public bool MoveNext()
 1397            {
 1398                // PERF: keep this method small to enable inlining.
 1399
 1400                if (_currentRowId >= _lastRowId)
 1401                {
 1402                    _currentRowId = EnumEnded;
 1403                    return false;
 1404                }
 1405                else
 1406                {
 1407                    _currentRowId++;
 1408                    return true;
 1409                }
 1410            }
 1411
 1412            object IEnumerator.Current
 1413            {
 1414                get { return Current; }
 1415            }
 1416
 1417            void IEnumerator.Reset()
 1418            {
 1419                throw new NotSupportedException();
 1420            }
 1421
 1422            void IDisposable.Dispose()
 1423            {
 1424            }
 1425        }
 1426    }
 1427
 1428    /// <summary>
 1429    /// Represents a collection of <see cref="TypeReferenceHandle"/>.
 1430    /// </summary>
 1431    public readonly struct ExportedTypeHandleCollection : IReadOnlyCollection<ExportedTypeHandle>
 1432    {
 1433        private readonly int _lastRowId;
 1434
 1435        // Creates collection that represents the entire TypeRef table.
 1436        internal ExportedTypeHandleCollection(int lastRowId)
 1437        {
 1438            _lastRowId = lastRowId;
 1439        }
 1440
 1441        public int Count
 1442        {
 1443            get { return _lastRowId; }
 1444        }
 1445
 1446        public Enumerator GetEnumerator()
 1447        {
 1448            return new Enumerator(_lastRowId);
 1449        }
 1450
 1451        IEnumerator<ExportedTypeHandle> IEnumerable<ExportedTypeHandle>.GetEnumerator()
 1452        {
 1453            return GetEnumerator();
 1454        }
 1455
 1456        IEnumerator IEnumerable.GetEnumerator()
 1457        {
 1458            return GetEnumerator();
 1459        }
 1460
 1461        public struct Enumerator : IEnumerator<ExportedTypeHandle>, IEnumerator
 1462        {
 1463            private readonly int _lastRowId;
 1464
 1465            // 0: initial state
 1466            // EnumEnded: enumeration ended
 1467            private int _currentRowId;
 1468
 1469            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 1470            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 1471
 1472            internal Enumerator(int lastRowId)
 1473            {
 1474                _lastRowId = lastRowId;
 1475                _currentRowId = 0;
 1476            }
 1477
 1478            public ExportedTypeHandle Current
 1479            {
 1480                get
 1481                {
 1482                    return ExportedTypeHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 1483                }
 1484            }
 1485
 1486            public bool MoveNext()
 1487            {
 1488                // PERF: keep this method small to enable inlining.
 1489
 1490                if (_currentRowId >= _lastRowId)
 1491                {
 1492                    _currentRowId = EnumEnded;
 1493                    return false;
 1494                }
 1495                else
 1496                {
 1497                    _currentRowId++;
 1498                    return true;
 1499                }
 1500            }
 1501
 1502            object IEnumerator.Current
 1503            {
 1504                get { return Current; }
 1505            }
 1506
 1507            void IEnumerator.Reset()
 1508            {
 1509                throw new NotSupportedException();
 1510            }
 1511
 1512            void IDisposable.Dispose()
 1513            {
 1514            }
 1515        }
 1516    }
 1517
 1518    /// <summary>
 1519    /// Represents a collection of <see cref="MemberReferenceHandle"/>.
 1520    /// </summary>
 1521    public readonly struct MemberReferenceHandleCollection : IReadOnlyCollection<MemberReferenceHandle>
 1522    {
 1523        private readonly int _lastRowId;
 1524
 1525        // Creates collection that represents the entire TypeRef table.
 1526        internal MemberReferenceHandleCollection(int lastRowId)
 01527        {
 01528            _lastRowId = lastRowId;
 01529        }
 1530
 1531        public int Count
 1532        {
 01533            get { return _lastRowId; }
 1534        }
 1535
 1536        public Enumerator GetEnumerator()
 01537        {
 01538            return new Enumerator(_lastRowId);
 01539        }
 1540
 1541        IEnumerator<MemberReferenceHandle> IEnumerable<MemberReferenceHandle>.GetEnumerator()
 01542        {
 01543            return GetEnumerator();
 01544        }
 1545
 1546        IEnumerator IEnumerable.GetEnumerator()
 01547        {
 01548            return GetEnumerator();
 01549        }
 1550
 1551        public struct Enumerator : IEnumerator<MemberReferenceHandle>, IEnumerator
 1552        {
 1553            private readonly int _lastRowId;
 1554
 1555            // 0: initial state
 1556            // EnumEnded: enumeration ended
 1557            private int _currentRowId;
 1558
 1559            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 1560            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 1561
 1562            internal Enumerator(int lastRowId)
 01563            {
 01564                _lastRowId = lastRowId;
 01565                _currentRowId = 0;
 01566            }
 1567
 1568            public MemberReferenceHandle Current
 1569            {
 1570                get
 01571                {
 01572                    return MemberReferenceHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 01573                }
 1574            }
 1575
 1576            public bool MoveNext()
 01577            {
 1578                // PERF: keep this method small to enable inlining.
 1579
 01580                if (_currentRowId >= _lastRowId)
 01581                {
 01582                    _currentRowId = EnumEnded;
 01583                    return false;
 1584                }
 1585                else
 01586                {
 01587                    _currentRowId++;
 01588                    return true;
 1589                }
 01590            }
 1591
 1592            object IEnumerator.Current
 1593            {
 01594                get { return Current; }
 1595            }
 1596
 1597            void IEnumerator.Reset()
 01598            {
 01599                throw new NotSupportedException();
 1600            }
 1601
 1602            void IDisposable.Dispose()
 01603            {
 01604            }
 1605        }
 1606    }
 1607
 1608    public readonly struct PropertyAccessors
 1609    {
 1610        // Workaround: JIT doesn't generate good code for nested structures, so use uints.
 1611
 1612        private readonly int _getterRowId;
 1613        private readonly int _setterRowId;
 1614        private readonly ImmutableArray<MethodDefinitionHandle> _others;
 1615
 1616        public MethodDefinitionHandle Getter { get { return MethodDefinitionHandle.FromRowId(_getterRowId); } }
 1617        public MethodDefinitionHandle Setter { get { return MethodDefinitionHandle.FromRowId(_setterRowId); } }
 1618        public ImmutableArray<MethodDefinitionHandle> Others { get { return _others; } }
 1619
 1620        internal PropertyAccessors(int getterRowId, int setterRowId, ImmutableArray<MethodDefinitionHandle> others)
 1621        {
 1622            _getterRowId = getterRowId;
 1623            _setterRowId = setterRowId;
 1624            _others = others;
 1625        }
 1626    }
 1627
 1628    public readonly struct EventAccessors
 1629    {
 1630        // Workaround: JIT doesn't generate good code for nested structures, so use uints.
 1631
 1632        private readonly int _adderRowId;
 1633        private readonly int _removerRowId;
 1634        private readonly int _raiserRowId;
 1635        private readonly ImmutableArray<MethodDefinitionHandle> _others;
 1636
 1637        public MethodDefinitionHandle Adder { get { return MethodDefinitionHandle.FromRowId(_adderRowId); } }
 1638        public MethodDefinitionHandle Remover { get { return MethodDefinitionHandle.FromRowId(_removerRowId); } }
 1639        public MethodDefinitionHandle Raiser { get { return MethodDefinitionHandle.FromRowId(_raiserRowId); } }
 1640        public ImmutableArray<MethodDefinitionHandle> Others { get { return _others; } }
 1641
 1642        internal EventAccessors(int adderRowId, int removerRowId, int raiserRowId, ImmutableArray<MethodDefinitionHandle
 1643        {
 1644            _adderRowId = adderRowId;
 1645            _removerRowId = removerRowId;
 1646            _raiserRowId = raiserRowId;
 1647            _others = others;
 1648        }
 1649    }
 1650
 1651    /// <summary>
 1652    /// Collection of assembly references.
 1653    /// </summary>
 1654    public readonly struct AssemblyReferenceHandleCollection : IReadOnlyCollection<AssemblyReferenceHandle>
 1655    {
 1656        private readonly MetadataReader _reader;
 1657
 1658        internal AssemblyReferenceHandleCollection(MetadataReader reader)
 1659        {
 1660            Debug.Assert(reader != null);
 1661            _reader = reader;
 1662        }
 1663
 1664        public int Count
 1665        {
 1666            get
 1667            {
 1668                return _reader.AssemblyRefTable.NumberOfNonVirtualRows + _reader.AssemblyRefTable.NumberOfVirtualRows;
 1669            }
 1670        }
 1671
 1672        public Enumerator GetEnumerator()
 1673        {
 1674            return new Enumerator(_reader);
 1675        }
 1676
 1677        IEnumerator<AssemblyReferenceHandle> IEnumerable<AssemblyReferenceHandle>.GetEnumerator()
 1678        {
 1679            return GetEnumerator();
 1680        }
 1681
 1682        IEnumerator IEnumerable.GetEnumerator()
 1683        {
 1684            return GetEnumerator();
 1685        }
 1686
 1687        public struct Enumerator : IEnumerator<AssemblyReferenceHandle>, IEnumerator
 1688        {
 1689            private readonly MetadataReader _reader;
 1690
 1691            // 0: initial state
 1692            // EnumEnded: enumeration ended
 1693            private int _currentRowId;
 1694
 1695            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 1696            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 1697
 1698            private int _virtualRowId;
 1699
 1700            internal Enumerator(MetadataReader reader)
 1701            {
 1702                _reader = reader;
 1703                _currentRowId = 0;
 1704                _virtualRowId = -1;
 1705            }
 1706
 1707            public AssemblyReferenceHandle Current
 1708            {
 1709                get
 1710                {
 1711                    if (_virtualRowId >= 0)
 1712                    {
 1713                        if (_virtualRowId == EnumEnded)
 1714                        {
 1715                            return default(AssemblyReferenceHandle);
 1716                        }
 1717
 1718                        return AssemblyReferenceHandle.FromVirtualIndex((AssemblyReferenceHandle.VirtualIndex)((uint)_vi
 1719                    }
 1720                    else
 1721                    {
 1722                        return AssemblyReferenceHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 1723                    }
 1724                }
 1725            }
 1726
 1727            public bool MoveNext()
 1728            {
 1729                if (_currentRowId < _reader.AssemblyRefTable.NumberOfNonVirtualRows)
 1730                {
 1731                    _currentRowId++;
 1732                    return true;
 1733                }
 1734
 1735                if (_virtualRowId < _reader.AssemblyRefTable.NumberOfVirtualRows - 1)
 1736                {
 1737                    _virtualRowId++;
 1738                    return true;
 1739                }
 1740
 1741                _currentRowId = EnumEnded;
 1742                _virtualRowId = EnumEnded;
 1743                return false;
 1744            }
 1745
 1746            object IEnumerator.Current
 1747            {
 1748                get { return Current; }
 1749            }
 1750
 1751            void IEnumerator.Reset()
 1752            {
 1753                throw new NotSupportedException();
 1754            }
 1755
 1756            void IDisposable.Dispose()
 1757            {
 1758            }
 1759        }
 1760    }
 1761
 1762    /// <summary>
 1763    /// Represents a collection of <see cref="ManifestResourceHandle"/>.
 1764    /// </summary>
 1765    public readonly struct ManifestResourceHandleCollection : IReadOnlyCollection<ManifestResourceHandle>
 1766    {
 1767        private readonly int _lastRowId;
 1768
 1769        // Creates collection that represents the entire ManifestResource table.
 1770        internal ManifestResourceHandleCollection(int lastRowId)
 1771        {
 1772            _lastRowId = lastRowId;
 1773        }
 1774
 1775        public int Count
 1776        {
 1777            get { return _lastRowId; }
 1778        }
 1779
 1780        public Enumerator GetEnumerator()
 1781        {
 1782            return new Enumerator(_lastRowId);
 1783        }
 1784
 1785        IEnumerator<ManifestResourceHandle> IEnumerable<ManifestResourceHandle>.GetEnumerator()
 1786        {
 1787            return GetEnumerator();
 1788        }
 1789
 1790        IEnumerator IEnumerable.GetEnumerator()
 1791        {
 1792            return GetEnumerator();
 1793        }
 1794
 1795        public struct Enumerator : IEnumerator<ManifestResourceHandle>, IEnumerator
 1796        {
 1797            private readonly int _lastRowId;
 1798
 1799            // 0: initial state
 1800            // EnumEnded: enumeration ended
 1801            private int _currentRowId;
 1802
 1803            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 1804            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 1805
 1806            internal Enumerator(int lastRowId)
 1807            {
 1808                _lastRowId = lastRowId;
 1809                _currentRowId = 0;
 1810            }
 1811
 1812            public ManifestResourceHandle Current
 1813            {
 1814                get
 1815                {
 1816                    return ManifestResourceHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 1817                }
 1818            }
 1819
 1820            public bool MoveNext()
 1821            {
 1822                // PERF: keep this method small to enable inlining.
 1823
 1824                if (_currentRowId >= _lastRowId)
 1825                {
 1826                    _currentRowId = EnumEnded;
 1827                    return false;
 1828                }
 1829                else
 1830                {
 1831                    _currentRowId++;
 1832                    return true;
 1833                }
 1834            }
 1835
 1836            object IEnumerator.Current
 1837            {
 1838                get { return Current; }
 1839            }
 1840
 1841            void IEnumerator.Reset()
 1842            {
 1843                throw new NotSupportedException();
 1844            }
 1845
 1846            void IDisposable.Dispose()
 1847            {
 1848            }
 1849        }
 1850    }
 1851
 1852    /// <summary>
 1853    /// Represents a collection of <see cref="AssemblyFileHandle"/>.
 1854    /// </summary>
 1855    public readonly struct AssemblyFileHandleCollection : IReadOnlyCollection<AssemblyFileHandle>
 1856    {
 1857        private readonly int _lastRowId;
 1858
 1859        // Creates collection that represents the entire AssemblyFile table.
 1860        internal AssemblyFileHandleCollection(int lastRowId)
 1861        {
 1862            _lastRowId = lastRowId;
 1863        }
 1864
 1865        public int Count
 1866        {
 1867            get { return _lastRowId; }
 1868        }
 1869
 1870        public Enumerator GetEnumerator()
 1871        {
 1872            return new Enumerator(_lastRowId);
 1873        }
 1874
 1875        IEnumerator<AssemblyFileHandle> IEnumerable<AssemblyFileHandle>.GetEnumerator()
 1876        {
 1877            return GetEnumerator();
 1878        }
 1879
 1880        IEnumerator IEnumerable.GetEnumerator()
 1881        {
 1882            return GetEnumerator();
 1883        }
 1884
 1885        public struct Enumerator : IEnumerator<AssemblyFileHandle>, IEnumerator
 1886        {
 1887            private readonly int _lastRowId;
 1888
 1889            // 0: initial state
 1890            // EnumEnded: enumeration ended
 1891            private int _currentRowId;
 1892
 1893            // greater than any RowId and with last 24 bits clear, so that Current returns nil token
 1894            private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1;
 1895
 1896            internal Enumerator(int lastRowId)
 1897            {
 1898                _lastRowId = lastRowId;
 1899                _currentRowId = 0;
 1900            }
 1901
 1902            public AssemblyFileHandle Current
 1903            {
 1904                get
 1905                {
 1906                    return AssemblyFileHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask));
 1907                }
 1908            }
 1909
 1910            public bool MoveNext()
 1911            {
 1912                // PERF: keep this method small to enable inlining.
 1913
 1914                if (_currentRowId >= _lastRowId)
 1915                {
 1916                    _currentRowId = EnumEnded;
 1917                    return false;
 1918                }
 1919                else
 1920                {
 1921                    _currentRowId++;
 1922                    return true;
 1923                }
 1924            }
 1925
 1926            object IEnumerator.Current
 1927            {
 1928                get { return Current; }
 1929            }
 1930
 1931            void IEnumerator.Reset()
 1932            {
 1933                throw new NotSupportedException();
 1934            }
 1935
 1936            void IDisposable.Dispose()
 1937            {
 1938            }
 1939        }
 1940    }
 1941}
 1942