| | | 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 | | public readonly struct ExceptionRegion |
| | | 7 | | { |
| | | 8 | | private readonly ExceptionRegionKind _kind; |
| | | 9 | | private readonly int _tryOffset; |
| | | 10 | | private readonly int _tryLength; |
| | | 11 | | private readonly int _handlerOffset; |
| | | 12 | | private readonly int _handlerLength; |
| | | 13 | | private readonly int _classTokenOrFilterOffset; |
| | | 14 | | |
| | | 15 | | internal ExceptionRegion( |
| | | 16 | | ExceptionRegionKind kind, |
| | | 17 | | int tryOffset, |
| | | 18 | | int tryLength, |
| | | 19 | | int handlerOffset, |
| | | 20 | | int handlerLength, |
| | | 21 | | int classTokenOrFilterOffset) |
| | 0 | 22 | | { |
| | 0 | 23 | | _kind = kind; |
| | 0 | 24 | | _tryOffset = tryOffset; |
| | 0 | 25 | | _tryLength = tryLength; |
| | 0 | 26 | | _handlerOffset = handlerOffset; |
| | 0 | 27 | | _handlerLength = handlerLength; |
| | 0 | 28 | | _classTokenOrFilterOffset = classTokenOrFilterOffset; |
| | 0 | 29 | | } |
| | | 30 | | |
| | | 31 | | public ExceptionRegionKind Kind |
| | | 32 | | { |
| | 0 | 33 | | get { return _kind; } |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Start IL offset of the try block. |
| | | 38 | | /// </summary> |
| | | 39 | | public int TryOffset |
| | | 40 | | { |
| | 0 | 41 | | get { return _tryOffset; } |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Length in bytes of try block. |
| | | 46 | | /// </summary> |
| | | 47 | | public int TryLength |
| | | 48 | | { |
| | 0 | 49 | | get { return _tryLength; } |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Start IL offset of the exception handler. |
| | | 54 | | /// </summary> |
| | | 55 | | public int HandlerOffset |
| | | 56 | | { |
| | 0 | 57 | | get { return _handlerOffset; } |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Length in bytes of the exception handler. |
| | | 62 | | /// </summary> |
| | | 63 | | public int HandlerLength |
| | | 64 | | { |
| | 0 | 65 | | get { return _handlerLength; } |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// IL offset of the start of the filter block, or -1 if the region is not a filter. |
| | | 70 | | /// </summary> |
| | | 71 | | public int FilterOffset |
| | | 72 | | { |
| | 0 | 73 | | get { return (Kind == ExceptionRegionKind.Filter) ? _classTokenOrFilterOffset : -1; } |
| | | 74 | | } |
| | | 75 | | |
| | | 76 | | /// <summary> |
| | | 77 | | /// Returns a TypeRef, TypeDef, or TypeSpec handle if the region represents a catch, nil token otherwise. |
| | | 78 | | /// </summary> |
| | | 79 | | public EntityHandle CatchType |
| | | 80 | | { |
| | 0 | 81 | | get { return (Kind == ExceptionRegionKind.Catch) ? new EntityHandle((uint)_classTokenOrFilterOffset) : defau |
| | | 82 | | } |
| | | 83 | | } |
| | | 84 | | } |
| | | 85 | | |