| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Diagnostics; |
| | | 7 | | using System.Reflection.Metadata.Ecma335; |
| | | 8 | | |
| | | 9 | | namespace System.Reflection.Metadata |
| | | 10 | | { |
| | | 11 | | public readonly struct DocumentHandleCollection : IReadOnlyCollection<DocumentHandle> |
| | | 12 | | { |
| | | 13 | | private readonly MetadataReader _reader; |
| | | 14 | | |
| | | 15 | | private readonly int _firstRowId; |
| | | 16 | | private readonly int _lastRowId; |
| | | 17 | | |
| | | 18 | | internal DocumentHandleCollection(MetadataReader reader) |
| | | 19 | | { |
| | | 20 | | Debug.Assert(reader != null); |
| | | 21 | | _reader = reader; |
| | | 22 | | |
| | | 23 | | _firstRowId = 1; |
| | | 24 | | _lastRowId = reader.DocumentTable.NumberOfRows; |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | public int Count |
| | | 28 | | { |
| | | 29 | | get |
| | | 30 | | { |
| | | 31 | | return _lastRowId - _firstRowId + 1; |
| | | 32 | | } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public Enumerator GetEnumerator() |
| | | 36 | | { |
| | | 37 | | return new Enumerator(_reader, _firstRowId, _lastRowId); |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | IEnumerator<DocumentHandle> IEnumerable<DocumentHandle>.GetEnumerator() |
| | | 41 | | { |
| | | 42 | | return GetEnumerator(); |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | IEnumerator IEnumerable.GetEnumerator() |
| | | 46 | | { |
| | | 47 | | return GetEnumerator(); |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | public struct Enumerator : IEnumerator<DocumentHandle>, IEnumerator |
| | | 51 | | { |
| | | 52 | | private readonly MetadataReader _reader; |
| | | 53 | | private readonly int _lastRowId; // inclusive |
| | | 54 | | |
| | | 55 | | // first Parameter rid - 1: initial state |
| | | 56 | | // EnumEnded: enumeration ended |
| | | 57 | | private int _currentRowId; |
| | | 58 | | |
| | | 59 | | // greater than any RowId and with last 24 bits clear, so that Current returns nil token |
| | | 60 | | private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1; |
| | | 61 | | |
| | | 62 | | internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId) |
| | | 63 | | { |
| | | 64 | | _reader = reader; |
| | | 65 | | _lastRowId = lastRowId; |
| | | 66 | | _currentRowId = firstRowId - 1; |
| | | 67 | | } |
| | | 68 | | |
| | | 69 | | public DocumentHandle Current |
| | | 70 | | { |
| | | 71 | | get |
| | | 72 | | { |
| | | 73 | | // PERF: keep this code small to enable inlining. |
| | | 74 | | return DocumentHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask)); |
| | | 75 | | } |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | public bool MoveNext() |
| | | 79 | | { |
| | | 80 | | // PERF: keep this code small to enable inlining. |
| | | 81 | | |
| | | 82 | | if (_currentRowId >= _lastRowId) |
| | | 83 | | { |
| | | 84 | | _currentRowId = EnumEnded; |
| | | 85 | | return false; |
| | | 86 | | } |
| | | 87 | | else |
| | | 88 | | { |
| | | 89 | | _currentRowId++; |
| | | 90 | | return true; |
| | | 91 | | } |
| | | 92 | | } |
| | | 93 | | |
| | | 94 | | object IEnumerator.Current |
| | | 95 | | { |
| | | 96 | | get { return Current; } |
| | | 97 | | } |
| | | 98 | | |
| | | 99 | | void IEnumerator.Reset() |
| | | 100 | | { |
| | | 101 | | throw new NotSupportedException(); |
| | | 102 | | } |
| | | 103 | | |
| | | 104 | | void IDisposable.Dispose() |
| | | 105 | | { |
| | | 106 | | } |
| | | 107 | | } |
| | | 108 | | } |
| | | 109 | | |
| | | 110 | | public readonly struct MethodDebugInformationHandleCollection : IReadOnlyCollection<MethodDebugInformationHandle> |
| | | 111 | | { |
| | | 112 | | private readonly MetadataReader _reader; |
| | | 113 | | |
| | | 114 | | private readonly int _firstRowId; |
| | | 115 | | private readonly int _lastRowId; |
| | | 116 | | |
| | | 117 | | internal MethodDebugInformationHandleCollection(MetadataReader reader) |
| | | 118 | | { |
| | | 119 | | Debug.Assert(reader != null); |
| | | 120 | | _reader = reader; |
| | | 121 | | |
| | | 122 | | _firstRowId = 1; |
| | | 123 | | _lastRowId = reader.MethodDebugInformationTable.NumberOfRows; |
| | | 124 | | } |
| | | 125 | | |
| | | 126 | | public int Count |
| | | 127 | | { |
| | | 128 | | get |
| | | 129 | | { |
| | | 130 | | return _lastRowId - _firstRowId + 1; |
| | | 131 | | } |
| | | 132 | | } |
| | | 133 | | |
| | | 134 | | public Enumerator GetEnumerator() |
| | | 135 | | { |
| | | 136 | | return new Enumerator(_reader, _firstRowId, _lastRowId); |
| | | 137 | | } |
| | | 138 | | |
| | | 139 | | IEnumerator<MethodDebugInformationHandle> IEnumerable<MethodDebugInformationHandle>.GetEnumerator() |
| | | 140 | | { |
| | | 141 | | return GetEnumerator(); |
| | | 142 | | } |
| | | 143 | | |
| | | 144 | | IEnumerator IEnumerable.GetEnumerator() |
| | | 145 | | { |
| | | 146 | | return GetEnumerator(); |
| | | 147 | | } |
| | | 148 | | |
| | | 149 | | public struct Enumerator : IEnumerator<MethodDebugInformationHandle>, IEnumerator |
| | | 150 | | { |
| | | 151 | | private readonly MetadataReader _reader; |
| | | 152 | | private readonly int _lastRowId; // inclusive |
| | | 153 | | |
| | | 154 | | // first Parameter rid - 1: initial state |
| | | 155 | | // EnumEnded: enumeration ended |
| | | 156 | | private int _currentRowId; |
| | | 157 | | |
| | | 158 | | // greater than any RowId and with last 24 bits clear, so that Current returns nil token |
| | | 159 | | private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1; |
| | | 160 | | |
| | | 161 | | internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId) |
| | | 162 | | { |
| | | 163 | | _reader = reader; |
| | | 164 | | _lastRowId = lastRowId; |
| | | 165 | | _currentRowId = firstRowId - 1; |
| | | 166 | | } |
| | | 167 | | |
| | | 168 | | public MethodDebugInformationHandle Current |
| | | 169 | | { |
| | | 170 | | get |
| | | 171 | | { |
| | | 172 | | // PERF: keep this code small to enable inlining. |
| | | 173 | | return MethodDebugInformationHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask)); |
| | | 174 | | } |
| | | 175 | | } |
| | | 176 | | |
| | | 177 | | public bool MoveNext() |
| | | 178 | | { |
| | | 179 | | // PERF: keep this code small to enable inlining. |
| | | 180 | | |
| | | 181 | | if (_currentRowId >= _lastRowId) |
| | | 182 | | { |
| | | 183 | | _currentRowId = EnumEnded; |
| | | 184 | | return false; |
| | | 185 | | } |
| | | 186 | | else |
| | | 187 | | { |
| | | 188 | | _currentRowId++; |
| | | 189 | | return true; |
| | | 190 | | } |
| | | 191 | | } |
| | | 192 | | |
| | | 193 | | object IEnumerator.Current |
| | | 194 | | { |
| | | 195 | | get { return Current; } |
| | | 196 | | } |
| | | 197 | | |
| | | 198 | | void IEnumerator.Reset() |
| | | 199 | | { |
| | | 200 | | throw new NotSupportedException(); |
| | | 201 | | } |
| | | 202 | | |
| | | 203 | | void IDisposable.Dispose() |
| | | 204 | | { |
| | | 205 | | } |
| | | 206 | | } |
| | | 207 | | } |
| | | 208 | | |
| | | 209 | | public readonly struct LocalScopeHandleCollection : IReadOnlyCollection<LocalScopeHandle> |
| | | 210 | | { |
| | | 211 | | private readonly MetadataReader _reader; |
| | | 212 | | |
| | | 213 | | private readonly int _firstRowId; |
| | | 214 | | private readonly int _lastRowId; |
| | | 215 | | |
| | | 216 | | internal LocalScopeHandleCollection(MetadataReader reader, int methodDefinitionRowId) |
| | | 217 | | { |
| | | 218 | | Debug.Assert(reader != null); |
| | | 219 | | _reader = reader; |
| | | 220 | | |
| | | 221 | | if (methodDefinitionRowId == 0) |
| | | 222 | | { |
| | | 223 | | _firstRowId = 1; |
| | | 224 | | _lastRowId = reader.LocalScopeTable.NumberOfRows; |
| | | 225 | | } |
| | | 226 | | else |
| | | 227 | | { |
| | | 228 | | reader.LocalScopeTable.GetLocalScopeRange(methodDefinitionRowId, out _firstRowId, out _lastRowId); |
| | | 229 | | } |
| | | 230 | | } |
| | | 231 | | |
| | | 232 | | public int Count |
| | | 233 | | { |
| | | 234 | | get |
| | | 235 | | { |
| | | 236 | | return _lastRowId - _firstRowId + 1; |
| | | 237 | | } |
| | | 238 | | } |
| | | 239 | | |
| | | 240 | | public Enumerator GetEnumerator() |
| | | 241 | | { |
| | | 242 | | return new Enumerator(_reader, _firstRowId, _lastRowId); |
| | | 243 | | } |
| | | 244 | | |
| | | 245 | | IEnumerator<LocalScopeHandle> IEnumerable<LocalScopeHandle>.GetEnumerator() |
| | | 246 | | { |
| | | 247 | | return GetEnumerator(); |
| | | 248 | | } |
| | | 249 | | |
| | | 250 | | IEnumerator IEnumerable.GetEnumerator() |
| | | 251 | | { |
| | | 252 | | return GetEnumerator(); |
| | | 253 | | } |
| | | 254 | | |
| | | 255 | | public struct Enumerator : IEnumerator<LocalScopeHandle>, IEnumerator |
| | | 256 | | { |
| | | 257 | | private readonly MetadataReader _reader; |
| | | 258 | | private readonly int _lastRowId; // inclusive |
| | | 259 | | |
| | | 260 | | // first Parameter rid - 1: initial state |
| | | 261 | | // EnumEnded: enumeration ended |
| | | 262 | | private int _currentRowId; |
| | | 263 | | |
| | | 264 | | // greater than any RowId and with last 24 bits clear, so that Current returns nil token |
| | | 265 | | private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1; |
| | | 266 | | |
| | | 267 | | internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId) |
| | | 268 | | { |
| | | 269 | | _reader = reader; |
| | | 270 | | _lastRowId = lastRowId; |
| | | 271 | | _currentRowId = firstRowId - 1; |
| | | 272 | | } |
| | | 273 | | |
| | | 274 | | public LocalScopeHandle Current |
| | | 275 | | { |
| | | 276 | | get |
| | | 277 | | { |
| | | 278 | | // PERF: keep this code small to enable inlining. |
| | | 279 | | return LocalScopeHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask)); |
| | | 280 | | } |
| | | 281 | | } |
| | | 282 | | |
| | | 283 | | public bool MoveNext() |
| | | 284 | | { |
| | | 285 | | // PERF: keep this code small to enable inlining. |
| | | 286 | | |
| | | 287 | | if (_currentRowId >= _lastRowId) |
| | | 288 | | { |
| | | 289 | | _currentRowId = EnumEnded; |
| | | 290 | | return false; |
| | | 291 | | } |
| | | 292 | | else |
| | | 293 | | { |
| | | 294 | | _currentRowId++; |
| | | 295 | | return true; |
| | | 296 | | } |
| | | 297 | | } |
| | | 298 | | |
| | | 299 | | object IEnumerator.Current |
| | | 300 | | { |
| | | 301 | | get { return Current; } |
| | | 302 | | } |
| | | 303 | | |
| | | 304 | | void IEnumerator.Reset() |
| | | 305 | | { |
| | | 306 | | throw new NotSupportedException(); |
| | | 307 | | } |
| | | 308 | | |
| | | 309 | | void IDisposable.Dispose() |
| | | 310 | | { |
| | | 311 | | } |
| | | 312 | | } |
| | | 313 | | |
| | | 314 | | public struct ChildrenEnumerator : IEnumerator<LocalScopeHandle>, IEnumerator |
| | | 315 | | { |
| | | 316 | | private readonly MetadataReader _reader; |
| | | 317 | | private readonly int _parentEndOffset; |
| | | 318 | | private readonly int _parentRowId; |
| | | 319 | | private readonly MethodDefinitionHandle _parentMethodRowId; |
| | | 320 | | |
| | | 321 | | // parent rid: initial state |
| | | 322 | | // EnumEnded: enumeration ended |
| | | 323 | | private int _currentRowId; |
| | | 324 | | |
| | | 325 | | // greater than any RowId and with last 24 bits clear, so that Current returns nil token |
| | | 326 | | private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1; |
| | | 327 | | |
| | | 328 | | internal ChildrenEnumerator(MetadataReader reader, int parentRowId) |
| | | 329 | | { |
| | | 330 | | _reader = reader; |
| | | 331 | | _parentEndOffset = reader.LocalScopeTable.GetEndOffset(parentRowId); |
| | | 332 | | _parentMethodRowId = reader.LocalScopeTable.GetMethod(parentRowId); |
| | | 333 | | _currentRowId = 0; |
| | | 334 | | _parentRowId = parentRowId; |
| | | 335 | | } |
| | | 336 | | |
| | | 337 | | public LocalScopeHandle Current |
| | | 338 | | { |
| | | 339 | | get |
| | | 340 | | { |
| | | 341 | | // PERF: keep this code small to enable inlining. |
| | | 342 | | return LocalScopeHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask)); |
| | | 343 | | } |
| | | 344 | | } |
| | | 345 | | |
| | | 346 | | public bool MoveNext() |
| | | 347 | | { |
| | | 348 | | int currentRowId = _currentRowId; |
| | | 349 | | if (currentRowId == EnumEnded) |
| | | 350 | | { |
| | | 351 | | return false; |
| | | 352 | | } |
| | | 353 | | |
| | | 354 | | int currentEndOffset; |
| | | 355 | | int nextRowId; |
| | | 356 | | if (currentRowId == 0) |
| | | 357 | | { |
| | | 358 | | currentEndOffset = -1; |
| | | 359 | | nextRowId = _parentRowId + 1; |
| | | 360 | | } |
| | | 361 | | else |
| | | 362 | | { |
| | | 363 | | currentEndOffset = _reader.LocalScopeTable.GetEndOffset(currentRowId); |
| | | 364 | | nextRowId = currentRowId + 1; |
| | | 365 | | } |
| | | 366 | | |
| | | 367 | | int rowCount = _reader.LocalScopeTable.NumberOfRows; |
| | | 368 | | |
| | | 369 | | while (true) |
| | | 370 | | { |
| | | 371 | | if (nextRowId > rowCount || |
| | | 372 | | _parentMethodRowId != _reader.LocalScopeTable.GetMethod(nextRowId)) |
| | | 373 | | { |
| | | 374 | | _currentRowId = EnumEnded; |
| | | 375 | | return false; |
| | | 376 | | } |
| | | 377 | | |
| | | 378 | | int nextEndOffset = _reader.LocalScopeTable.GetEndOffset(nextRowId); |
| | | 379 | | |
| | | 380 | | // If the end of the next scope is lesser than or equal the current end |
| | | 381 | | // then it's nested into the current scope and thus not a child of |
| | | 382 | | // the current scope parent. |
| | | 383 | | if (nextEndOffset > currentEndOffset) |
| | | 384 | | { |
| | | 385 | | // If the end of the next scope is greater than the parent end, |
| | | 386 | | // then we ran out of the children. |
| | | 387 | | if (nextEndOffset > _parentEndOffset) |
| | | 388 | | { |
| | | 389 | | _currentRowId = EnumEnded; |
| | | 390 | | return false; |
| | | 391 | | } |
| | | 392 | | |
| | | 393 | | _currentRowId = nextRowId; |
| | | 394 | | return true; |
| | | 395 | | } |
| | | 396 | | |
| | | 397 | | nextRowId++; |
| | | 398 | | } |
| | | 399 | | } |
| | | 400 | | |
| | | 401 | | object IEnumerator.Current |
| | | 402 | | { |
| | | 403 | | get { return Current; } |
| | | 404 | | } |
| | | 405 | | |
| | | 406 | | void IEnumerator.Reset() |
| | | 407 | | { |
| | | 408 | | throw new NotSupportedException(); |
| | | 409 | | } |
| | | 410 | | |
| | | 411 | | void IDisposable.Dispose() |
| | | 412 | | { |
| | | 413 | | } |
| | | 414 | | } |
| | | 415 | | } |
| | | 416 | | |
| | | 417 | | public readonly struct LocalVariableHandleCollection : IReadOnlyCollection<LocalVariableHandle> |
| | | 418 | | { |
| | | 419 | | private readonly MetadataReader _reader; |
| | | 420 | | |
| | | 421 | | private readonly int _firstRowId; |
| | | 422 | | private readonly int _lastRowId; |
| | | 423 | | |
| | | 424 | | internal LocalVariableHandleCollection(MetadataReader reader, LocalScopeHandle scope) |
| | | 425 | | { |
| | | 426 | | Debug.Assert(reader != null); |
| | | 427 | | _reader = reader; |
| | | 428 | | |
| | | 429 | | if (scope.IsNil) |
| | | 430 | | { |
| | | 431 | | _firstRowId = 1; |
| | | 432 | | _lastRowId = reader.LocalVariableTable.NumberOfRows; |
| | | 433 | | } |
| | | 434 | | else |
| | | 435 | | { |
| | | 436 | | reader.GetLocalVariableRange(scope, out _firstRowId, out _lastRowId); |
| | | 437 | | } |
| | | 438 | | } |
| | | 439 | | |
| | | 440 | | public int Count |
| | | 441 | | { |
| | | 442 | | get |
| | | 443 | | { |
| | | 444 | | return _lastRowId - _firstRowId + 1; |
| | | 445 | | } |
| | | 446 | | } |
| | | 447 | | |
| | | 448 | | public Enumerator GetEnumerator() |
| | | 449 | | { |
| | | 450 | | return new Enumerator(_reader, _firstRowId, _lastRowId); |
| | | 451 | | } |
| | | 452 | | |
| | | 453 | | IEnumerator<LocalVariableHandle> IEnumerable<LocalVariableHandle>.GetEnumerator() |
| | | 454 | | { |
| | | 455 | | return GetEnumerator(); |
| | | 456 | | } |
| | | 457 | | |
| | | 458 | | IEnumerator IEnumerable.GetEnumerator() |
| | | 459 | | { |
| | | 460 | | return GetEnumerator(); |
| | | 461 | | } |
| | | 462 | | |
| | | 463 | | public struct Enumerator : IEnumerator<LocalVariableHandle>, IEnumerator |
| | | 464 | | { |
| | | 465 | | private readonly MetadataReader _reader; |
| | | 466 | | private readonly int _lastRowId; // inclusive |
| | | 467 | | |
| | | 468 | | // first Parameter rid - 1: initial state |
| | | 469 | | // EnumEnded: enumeration ended |
| | | 470 | | private int _currentRowId; |
| | | 471 | | |
| | | 472 | | // greater than any RowId and with last 24 bits clear, so that Current returns nil token |
| | | 473 | | private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1; |
| | | 474 | | |
| | | 475 | | internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId) |
| | | 476 | | { |
| | | 477 | | _reader = reader; |
| | | 478 | | _lastRowId = lastRowId; |
| | | 479 | | _currentRowId = firstRowId - 1; |
| | | 480 | | } |
| | | 481 | | |
| | | 482 | | public LocalVariableHandle Current |
| | | 483 | | { |
| | | 484 | | get |
| | | 485 | | { |
| | | 486 | | // PERF: keep this code small to enable inlining. |
| | | 487 | | return LocalVariableHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask)); |
| | | 488 | | } |
| | | 489 | | } |
| | | 490 | | |
| | | 491 | | public bool MoveNext() |
| | | 492 | | { |
| | | 493 | | // PERF: keep this code small to enable inlining. |
| | | 494 | | |
| | | 495 | | if (_currentRowId >= _lastRowId) |
| | | 496 | | { |
| | | 497 | | _currentRowId = EnumEnded; |
| | | 498 | | return false; |
| | | 499 | | } |
| | | 500 | | else |
| | | 501 | | { |
| | | 502 | | _currentRowId++; |
| | | 503 | | return true; |
| | | 504 | | } |
| | | 505 | | } |
| | | 506 | | |
| | | 507 | | object IEnumerator.Current |
| | | 508 | | { |
| | | 509 | | get { return Current; } |
| | | 510 | | } |
| | | 511 | | |
| | | 512 | | void IEnumerator.Reset() |
| | | 513 | | { |
| | | 514 | | throw new NotSupportedException(); |
| | | 515 | | } |
| | | 516 | | |
| | | 517 | | void IDisposable.Dispose() |
| | | 518 | | { |
| | | 519 | | } |
| | | 520 | | } |
| | | 521 | | } |
| | | 522 | | |
| | | 523 | | public readonly struct LocalConstantHandleCollection : IReadOnlyCollection<LocalConstantHandle> |
| | | 524 | | { |
| | | 525 | | private readonly MetadataReader _reader; |
| | | 526 | | |
| | | 527 | | private readonly int _firstRowId; |
| | | 528 | | private readonly int _lastRowId; |
| | | 529 | | |
| | | 530 | | internal LocalConstantHandleCollection(MetadataReader reader, LocalScopeHandle scope) |
| | 0 | 531 | | { |
| | 0 | 532 | | Debug.Assert(reader != null); |
| | 0 | 533 | | _reader = reader; |
| | | 534 | | |
| | 0 | 535 | | if (scope.IsNil) |
| | 0 | 536 | | { |
| | 0 | 537 | | _firstRowId = 1; |
| | 0 | 538 | | _lastRowId = reader.LocalConstantTable.NumberOfRows; |
| | 0 | 539 | | } |
| | | 540 | | else |
| | 0 | 541 | | { |
| | 0 | 542 | | reader.GetLocalConstantRange(scope, out _firstRowId, out _lastRowId); |
| | 0 | 543 | | } |
| | 0 | 544 | | } |
| | | 545 | | |
| | | 546 | | public int Count |
| | | 547 | | { |
| | | 548 | | get |
| | 0 | 549 | | { |
| | 0 | 550 | | return _lastRowId - _firstRowId + 1; |
| | 0 | 551 | | } |
| | | 552 | | } |
| | | 553 | | |
| | | 554 | | public Enumerator GetEnumerator() |
| | 0 | 555 | | { |
| | 0 | 556 | | return new Enumerator(_reader, _firstRowId, _lastRowId); |
| | 0 | 557 | | } |
| | | 558 | | |
| | | 559 | | IEnumerator<LocalConstantHandle> IEnumerable<LocalConstantHandle>.GetEnumerator() |
| | 0 | 560 | | { |
| | 0 | 561 | | return GetEnumerator(); |
| | 0 | 562 | | } |
| | | 563 | | |
| | | 564 | | IEnumerator IEnumerable.GetEnumerator() |
| | 0 | 565 | | { |
| | 0 | 566 | | return GetEnumerator(); |
| | 0 | 567 | | } |
| | | 568 | | |
| | | 569 | | public struct Enumerator : IEnumerator<LocalConstantHandle>, IEnumerator |
| | | 570 | | { |
| | | 571 | | private readonly MetadataReader _reader; |
| | | 572 | | private readonly int _lastRowId; // inclusive |
| | | 573 | | |
| | | 574 | | // first Parameter rid - 1: initial state |
| | | 575 | | // EnumEnded: enumeration ended |
| | | 576 | | private int _currentRowId; |
| | | 577 | | |
| | | 578 | | // greater than any RowId and with last 24 bits clear, so that Current returns nil token |
| | | 579 | | private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1; |
| | | 580 | | |
| | | 581 | | internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId) |
| | 0 | 582 | | { |
| | 0 | 583 | | _reader = reader; |
| | 0 | 584 | | _lastRowId = lastRowId; |
| | 0 | 585 | | _currentRowId = firstRowId - 1; |
| | 0 | 586 | | } |
| | | 587 | | |
| | | 588 | | public LocalConstantHandle Current |
| | | 589 | | { |
| | | 590 | | get |
| | 0 | 591 | | { |
| | | 592 | | // PERF: keep this code small to enable inlining. |
| | 0 | 593 | | return LocalConstantHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask)); |
| | 0 | 594 | | } |
| | | 595 | | } |
| | | 596 | | |
| | | 597 | | public bool MoveNext() |
| | 0 | 598 | | { |
| | | 599 | | // PERF: keep this code small to enable inlining. |
| | | 600 | | |
| | 0 | 601 | | if (_currentRowId >= _lastRowId) |
| | 0 | 602 | | { |
| | 0 | 603 | | _currentRowId = EnumEnded; |
| | 0 | 604 | | return false; |
| | | 605 | | } |
| | | 606 | | else |
| | 0 | 607 | | { |
| | 0 | 608 | | _currentRowId++; |
| | 0 | 609 | | return true; |
| | | 610 | | } |
| | 0 | 611 | | } |
| | | 612 | | |
| | | 613 | | object IEnumerator.Current |
| | | 614 | | { |
| | 0 | 615 | | get { return Current; } |
| | | 616 | | } |
| | | 617 | | |
| | | 618 | | void IEnumerator.Reset() |
| | 0 | 619 | | { |
| | 0 | 620 | | throw new NotSupportedException(); |
| | | 621 | | } |
| | | 622 | | |
| | | 623 | | void IDisposable.Dispose() |
| | 0 | 624 | | { |
| | 0 | 625 | | } |
| | | 626 | | } |
| | | 627 | | } |
| | | 628 | | |
| | | 629 | | public readonly struct ImportScopeCollection : IReadOnlyCollection<ImportScopeHandle> |
| | | 630 | | { |
| | | 631 | | private readonly MetadataReader _reader; |
| | | 632 | | |
| | | 633 | | private readonly int _firstRowId; |
| | | 634 | | private readonly int _lastRowId; |
| | | 635 | | |
| | | 636 | | internal ImportScopeCollection(MetadataReader reader) |
| | | 637 | | { |
| | | 638 | | Debug.Assert(reader != null); |
| | | 639 | | _reader = reader; |
| | | 640 | | |
| | | 641 | | _firstRowId = 1; |
| | | 642 | | _lastRowId = reader.ImportScopeTable.NumberOfRows; |
| | | 643 | | } |
| | | 644 | | |
| | | 645 | | public int Count |
| | | 646 | | { |
| | | 647 | | get |
| | | 648 | | { |
| | | 649 | | return _lastRowId - _firstRowId + 1; |
| | | 650 | | } |
| | | 651 | | } |
| | | 652 | | |
| | | 653 | | public Enumerator GetEnumerator() |
| | | 654 | | { |
| | | 655 | | return new Enumerator(_reader, _firstRowId, _lastRowId); |
| | | 656 | | } |
| | | 657 | | |
| | | 658 | | IEnumerator<ImportScopeHandle> IEnumerable<ImportScopeHandle>.GetEnumerator() |
| | | 659 | | { |
| | | 660 | | return GetEnumerator(); |
| | | 661 | | } |
| | | 662 | | |
| | | 663 | | IEnumerator IEnumerable.GetEnumerator() |
| | | 664 | | { |
| | | 665 | | return GetEnumerator(); |
| | | 666 | | } |
| | | 667 | | |
| | | 668 | | public struct Enumerator : IEnumerator<ImportScopeHandle>, IEnumerator |
| | | 669 | | { |
| | | 670 | | private readonly MetadataReader _reader; |
| | | 671 | | private readonly int _lastRowId; // inclusive |
| | | 672 | | |
| | | 673 | | // first Parameter rid - 1: initial state |
| | | 674 | | // EnumEnded: enumeration ended |
| | | 675 | | private int _currentRowId; |
| | | 676 | | |
| | | 677 | | // greater than any RowId and with last 24 bits clear, so that Current returns nil token |
| | | 678 | | private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1; |
| | | 679 | | |
| | | 680 | | internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId) |
| | | 681 | | { |
| | | 682 | | _reader = reader; |
| | | 683 | | _lastRowId = lastRowId; |
| | | 684 | | _currentRowId = firstRowId - 1; |
| | | 685 | | } |
| | | 686 | | |
| | | 687 | | public ImportScopeHandle Current |
| | | 688 | | { |
| | | 689 | | get |
| | | 690 | | { |
| | | 691 | | // PERF: keep this code small to enable inlining. |
| | | 692 | | return ImportScopeHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask)); |
| | | 693 | | } |
| | | 694 | | } |
| | | 695 | | |
| | | 696 | | public bool MoveNext() |
| | | 697 | | { |
| | | 698 | | // PERF: keep this code small to enable inlining. |
| | | 699 | | |
| | | 700 | | if (_currentRowId >= _lastRowId) |
| | | 701 | | { |
| | | 702 | | _currentRowId = EnumEnded; |
| | | 703 | | return false; |
| | | 704 | | } |
| | | 705 | | else |
| | | 706 | | { |
| | | 707 | | _currentRowId++; |
| | | 708 | | return true; |
| | | 709 | | } |
| | | 710 | | } |
| | | 711 | | |
| | | 712 | | object IEnumerator.Current |
| | | 713 | | { |
| | | 714 | | get { return Current; } |
| | | 715 | | } |
| | | 716 | | |
| | | 717 | | void IEnumerator.Reset() |
| | | 718 | | { |
| | | 719 | | throw new NotSupportedException(); |
| | | 720 | | } |
| | | 721 | | |
| | | 722 | | void IDisposable.Dispose() |
| | | 723 | | { |
| | | 724 | | } |
| | | 725 | | } |
| | | 726 | | } |
| | | 727 | | |
| | | 728 | | public readonly struct CustomDebugInformationHandleCollection : IReadOnlyCollection<CustomDebugInformationHandle> |
| | | 729 | | { |
| | | 730 | | private readonly MetadataReader _reader; |
| | | 731 | | |
| | | 732 | | private readonly int _firstRowId; |
| | | 733 | | private readonly int _lastRowId; |
| | | 734 | | |
| | | 735 | | internal CustomDebugInformationHandleCollection(MetadataReader reader) |
| | | 736 | | { |
| | | 737 | | Debug.Assert(reader != null); |
| | | 738 | | _reader = reader; |
| | | 739 | | |
| | | 740 | | _firstRowId = 1; |
| | | 741 | | _lastRowId = reader.CustomDebugInformationTable.NumberOfRows; |
| | | 742 | | } |
| | | 743 | | |
| | | 744 | | internal CustomDebugInformationHandleCollection(MetadataReader reader, EntityHandle handle) |
| | | 745 | | { |
| | | 746 | | Debug.Assert(reader != null); |
| | | 747 | | |
| | | 748 | | _reader = reader; |
| | | 749 | | reader.CustomDebugInformationTable.GetRange(handle, out _firstRowId, out _lastRowId); |
| | | 750 | | } |
| | | 751 | | |
| | | 752 | | public int Count |
| | | 753 | | { |
| | | 754 | | get |
| | | 755 | | { |
| | | 756 | | return _lastRowId - _firstRowId + 1; |
| | | 757 | | } |
| | | 758 | | } |
| | | 759 | | |
| | | 760 | | public Enumerator GetEnumerator() |
| | | 761 | | { |
| | | 762 | | return new Enumerator(_reader, _firstRowId, _lastRowId); |
| | | 763 | | } |
| | | 764 | | |
| | | 765 | | IEnumerator<CustomDebugInformationHandle> IEnumerable<CustomDebugInformationHandle>.GetEnumerator() |
| | | 766 | | { |
| | | 767 | | return GetEnumerator(); |
| | | 768 | | } |
| | | 769 | | |
| | | 770 | | IEnumerator IEnumerable.GetEnumerator() |
| | | 771 | | { |
| | | 772 | | return GetEnumerator(); |
| | | 773 | | } |
| | | 774 | | |
| | | 775 | | public struct Enumerator : IEnumerator<CustomDebugInformationHandle>, IEnumerator |
| | | 776 | | { |
| | | 777 | | private readonly MetadataReader _reader; |
| | | 778 | | private readonly int _lastRowId; // inclusive |
| | | 779 | | |
| | | 780 | | // first Parameter rid - 1: initial state |
| | | 781 | | // EnumEnded: enumeration ended |
| | | 782 | | private int _currentRowId; |
| | | 783 | | |
| | | 784 | | // greater than any RowId and with last 24 bits clear, so that Current returns nil token |
| | | 785 | | private const int EnumEnded = (int)TokenTypeIds.RIDMask + 1; |
| | | 786 | | |
| | | 787 | | internal Enumerator(MetadataReader reader, int firstRowId, int lastRowId) |
| | | 788 | | { |
| | | 789 | | _reader = reader; |
| | | 790 | | _lastRowId = lastRowId; |
| | | 791 | | _currentRowId = firstRowId - 1; |
| | | 792 | | } |
| | | 793 | | |
| | | 794 | | public CustomDebugInformationHandle Current |
| | | 795 | | { |
| | | 796 | | get |
| | | 797 | | { |
| | | 798 | | // PERF: keep this code small to enable inlining. |
| | | 799 | | return CustomDebugInformationHandle.FromRowId((int)(_currentRowId & TokenTypeIds.RIDMask)); |
| | | 800 | | } |
| | | 801 | | } |
| | | 802 | | |
| | | 803 | | public bool MoveNext() |
| | | 804 | | { |
| | | 805 | | // PERF: keep this code small to enable inlining. |
| | | 806 | | |
| | | 807 | | if (_currentRowId >= _lastRowId) |
| | | 808 | | { |
| | | 809 | | _currentRowId = EnumEnded; |
| | | 810 | | return false; |
| | | 811 | | } |
| | | 812 | | else |
| | | 813 | | { |
| | | 814 | | _currentRowId++; |
| | | 815 | | return true; |
| | | 816 | | } |
| | | 817 | | } |
| | | 818 | | |
| | | 819 | | object IEnumerator.Current |
| | | 820 | | { |
| | | 821 | | get { return Current; } |
| | | 822 | | } |
| | | 823 | | |
| | | 824 | | void IEnumerator.Reset() |
| | | 825 | | { |
| | | 826 | | throw new NotSupportedException(); |
| | | 827 | | } |
| | | 828 | | |
| | | 829 | | void IDisposable.Dispose() |
| | | 830 | | { |
| | | 831 | | } |
| | | 832 | | } |
| | | 833 | | } |
| | | 834 | | } |
| | | 835 | | |