| | | 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 | | namespace System.Reflection.Metadata |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Scope of local variables and constants. Stored in debug metadata. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <remarks> |
| | | 10 | | /// See https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.Metadata/specs/PortablePdb-Metad |
| | | 11 | | /// </remarks> |
| | | 12 | | public readonly struct LocalScope |
| | | 13 | | { |
| | | 14 | | private readonly MetadataReader _reader; |
| | | 15 | | |
| | | 16 | | // Workaround: JIT doesn't generate good code for nested structures, so use RowId. |
| | | 17 | | private readonly int _rowId; |
| | | 18 | | |
| | | 19 | | internal LocalScope(MetadataReader reader, LocalScopeHandle handle) |
| | 0 | 20 | | { |
| | 0 | 21 | | _reader = reader; |
| | 0 | 22 | | _rowId = handle.RowId; |
| | 0 | 23 | | } |
| | | 24 | | |
| | 0 | 25 | | private LocalScopeHandle Handle => LocalScopeHandle.FromRowId(_rowId); |
| | | 26 | | |
| | 0 | 27 | | public MethodDefinitionHandle Method => _reader.LocalScopeTable.GetMethod(_rowId); |
| | 0 | 28 | | public ImportScopeHandle ImportScope => _reader.LocalScopeTable.GetImportScope(Handle); |
| | 0 | 29 | | public int StartOffset => _reader.LocalScopeTable.GetStartOffset(_rowId); |
| | 0 | 30 | | public int Length => _reader.LocalScopeTable.GetLength(_rowId); |
| | 0 | 31 | | public int EndOffset => _reader.LocalScopeTable.GetEndOffset(_rowId); |
| | | 32 | | |
| | | 33 | | public LocalVariableHandleCollection GetLocalVariables() |
| | 0 | 34 | | { |
| | 0 | 35 | | return new LocalVariableHandleCollection(_reader, Handle); |
| | 0 | 36 | | } |
| | | 37 | | |
| | | 38 | | public LocalConstantHandleCollection GetLocalConstants() |
| | 0 | 39 | | { |
| | 0 | 40 | | return new LocalConstantHandleCollection(_reader, Handle); |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | public LocalScopeHandleCollection.ChildrenEnumerator GetChildren() |
| | 0 | 44 | | { |
| | 0 | 45 | | return new LocalScopeHandleCollection.ChildrenEnumerator(_reader, _rowId); |
| | 0 | 46 | | } |
| | | 47 | | } |
| | | 48 | | } |
| | | 49 | | |