internal void AddUnchecked( ExceptionRegionKind kind, int tryOffset, int tryLength, int handlerOffset, int handlerLength, int catchTokenOrOffset) { if (HasSmallFormat) { Builder.WriteUInt16((ushort)kind); Builder.WriteUInt16((ushort)tryOffset); Builder.WriteByte((byte)tryLength); Builder.WriteUInt16((ushort)handlerOffset); Builder.WriteByte((byte)handlerLength); } else { Builder.WriteInt32((int)kind); Builder.WriteInt32(tryOffset); Builder.WriteInt32(tryLength); Builder.WriteInt32(handlerOffset); Builder.WriteInt32(handlerLength); } Builder.WriteInt32(catchTokenOrOffset); }
public _ExceptionRegionInfo(ExceptionHandlingClause aExceptionClause) { try { ExceptionClause = aExceptionClause; HandlerOffset = aExceptionClause.HandlerOffset; HandlerLength = aExceptionClause.HandlerLength; TryOffset = aExceptionClause.TryOffset; TryLength = aExceptionClause.TryLength; if (aExceptionClause.Flags == ExceptionHandlingClauseOptions.Clause) { Kind = ExceptionRegionKind.Catch; CatchType = aExceptionClause.CatchType; } else if (aExceptionClause.Flags.HasFlag(ExceptionHandlingClauseOptions.Fault)) { Kind = ExceptionRegionKind.Fault; } else if (aExceptionClause.Flags.HasFlag(ExceptionHandlingClauseOptions.Filter)) { Kind = ExceptionRegionKind.Filter; FilterOffset = aExceptionClause.FilterOffset; } else if (aExceptionClause.Flags.HasFlag(ExceptionHandlingClauseOptions.Finally)) { Kind = ExceptionRegionKind.Finally; } } catch (Exception ex) { } }
public _ExceptionRegionInfo(Module aModule, ExceptionRegion aExceptionRegion) { Module = aModule; ExceptionRegion = aExceptionRegion; HandlerOffset = aExceptionRegion.HandlerOffset; HandlerLength = aExceptionRegion.HandlerLength; TryOffset = aExceptionRegion.TryOffset; TryLength = aExceptionRegion.TryLength; FilterOffset = aExceptionRegion.FilterOffset; Kind = aExceptionRegion.Kind; }
internal ExceptionRegion( ExceptionRegionKind kind, int tryOffset, int tryLength, int handlerOffset, int handlerLength, int classTokenOrFilterOffset) { this.kind = kind; this.tryOffset = tryOffset; this.tryLength = tryLength; this.handlerOffset = handlerOffset; this.handlerLength = handlerLength; this.classTokenOrFilterOffset = classTokenOrFilterOffset; }
internal ExceptionRegion( ExceptionRegionKind kind, int tryOffset, int tryLength, int handlerOffset, int handlerLength, int classTokenOrFilterOffset) { this.kind = kind; this.tryOffset = tryOffset; this.tryLength = tryLength; this.handlerOffset = handlerOffset; this.handlerLength = handlerLength; this.classTokenOrFilterOffset = classTokenOrFilterOffset; }
internal ExceptionRegion( ExceptionRegionKind kind, int tryOffset, int tryLength, int handlerOffset, int handlerLength, int classTokenOrFilterOffset) { _kind = kind; _tryOffset = tryOffset; _tryLength = tryLength; _handlerOffset = handlerOffset; _handlerLength = handlerLength; _classTokenOrFilterOffset = classTokenOrFilterOffset; }
internal ExceptionRegion( ExceptionRegionKind kind, int tryOffset, int tryLength, int handlerOffset, int handlerLength, int classTokenOrFilterOffset) { _kind = kind; _tryOffset = tryOffset; _tryLength = tryLength; _handlerOffset = handlerOffset; _handlerLength = handlerLength; _classTokenOrFilterOffset = classTokenOrFilterOffset; }
public ExceptionHandlerInfo( ExceptionRegionKind kind, LabelHandle tryStart, LabelHandle tryEnd, LabelHandle handlerStart, LabelHandle handlerEnd, LabelHandle filterStart, EntityHandle catchType) { Kind = kind; TryStart = tryStart; TryEnd = tryEnd; HandlerStart = handlerStart; HandlerEnd = handlerEnd; FilterStart = filterStart; CatchType = catchType; }
public ExceptionHandlerInfo( ExceptionRegionKind kind, LabelHandle tryStart, LabelHandle tryEnd, LabelHandle handlerStart, LabelHandle handlerEnd, LabelHandle filterStart, EntityHandle catchType) { Kind = kind; TryStart = tryStart; TryEnd = tryEnd; HandlerStart = handlerStart; HandlerEnd = handlerEnd; FilterStart = filterStart; CatchType = catchType; }
private void AddExceptionRegion( ExceptionRegionKind kind, LabelHandle tryStart, LabelHandle tryEnd, LabelHandle handlerStart, LabelHandle handlerEnd, LabelHandle filterStart = default(LabelHandle), EntityHandle catchType = default(EntityHandle)) { ValidateLabel(tryStart, nameof(tryStart)); ValidateLabel(tryEnd, nameof(tryEnd)); ValidateLabel(handlerStart, nameof(handlerStart)); ValidateLabel(handlerEnd, nameof(handlerEnd)); _lazyExceptionHandlers ??= ImmutableArray.CreateBuilder <ExceptionHandlerInfo>(); _lazyExceptionHandlers.Add(new ExceptionHandlerInfo(kind, tryStart, tryEnd, handlerStart, handlerEnd, filterStart, catchType)); }
public void AddRegion( ExceptionRegionKind kind, int tryOffset, int tryLength, int handlerOffset, int handlerLength, EntityHandle catchType, int filterOffset) { if (_isSmallFormat) { Builder.WriteUInt16((ushort)kind); Builder.WriteUInt16((ushort)tryOffset); Builder.WriteByte((byte)tryLength); Builder.WriteUInt16((ushort)handlerOffset); Builder.WriteByte((byte)handlerLength); } else { Builder.WriteInt32((int)kind); Builder.WriteInt32(tryOffset); Builder.WriteInt32(tryLength); Builder.WriteInt32(handlerOffset); Builder.WriteInt32(handlerLength); } switch (kind) { case ExceptionRegionKind.Catch: Builder.WriteInt32(MetadataTokens.GetToken(catchType)); break; case ExceptionRegionKind.Filter: Builder.WriteInt32(filterOffset); break; default: Builder.WriteInt32(0); break; } }
private void AddExceptionRegion( ExceptionRegionKind kind, LabelHandle tryStart, LabelHandle tryEnd, LabelHandle handlerStart, LabelHandle handlerEnd, LabelHandle filterStart = default(LabelHandle), EntityHandle catchType = default(EntityHandle)) { ValidateLabel(tryStart, nameof(tryStart)); ValidateLabel(tryEnd, nameof(tryEnd)); ValidateLabel(handlerStart, nameof(handlerStart)); ValidateLabel(handlerEnd, nameof(handlerEnd)); if (_lazyExceptionHandlers == null) { _lazyExceptionHandlers = ImmutableArray.CreateBuilder<ExceptionHandlerInfo>(); } _lazyExceptionHandlers.Add(new ExceptionHandlerInfo(kind, tryStart, tryEnd, handlerStart, handlerEnd, filterStart, catchType)); }
/// <summary> /// Adds an exception clause. /// </summary> /// <param name="kind">Clause kind.</param> /// <param name="tryOffset">Try block start offset.</param> /// <param name="tryLength">Try block length.</param> /// <param name="handlerOffset">Handler start offset.</param> /// <param name="handlerLength">Handler length.</param> /// <param name="catchType"> /// <see cref="TypeDefinitionHandle"/>, <see cref="TypeReferenceHandle"/> or <see cref="TypeSpecificationHandle"/>, /// or nil if <paramref name="kind"/> is not <see cref="ExceptionRegionKind.Catch"/> /// </param> /// <param name="filterOffset"> /// Offset of the filter block, or 0 if the <paramref name="kind"/> is not <see cref="ExceptionRegionKind.Filter"/>. /// </param> /// <returns>Encoder for the next clause.</returns> /// <exception cref="ArgumentException"><paramref name="catchType"/> is invalid.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="kind"/> has invalid value.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="tryOffset"/>, <paramref name="tryLength"/>, <paramref name="handlerOffset"/> or <paramref name="handlerLength"/> is out of range. /// </exception> /// <exception cref="InvalidOperationException">Method body was not declared to have exception regions.</exception> public ExceptionRegionEncoder Add( ExceptionRegionKind kind, int tryOffset, int tryLength, int handlerOffset, int handlerLength, EntityHandle catchType = default(EntityHandle), int filterOffset = 0) { if (Builder == null) { Throw.InvalidOperation(SR.MethodHasNoExceptionRegions); } if (HasSmallFormat) { if (unchecked ((ushort)tryOffset) != tryOffset) { Throw.ArgumentOutOfRange(nameof(tryOffset)); } if (unchecked ((byte)tryLength) != tryLength) { Throw.ArgumentOutOfRange(nameof(tryLength)); } if (unchecked ((ushort)handlerOffset) != handlerOffset) { Throw.ArgumentOutOfRange(nameof(handlerOffset)); } if (unchecked ((byte)handlerLength) != handlerLength) { Throw.ArgumentOutOfRange(nameof(handlerLength)); } } else { if (tryOffset < 0) { Throw.ArgumentOutOfRange(nameof(tryOffset)); } if (tryLength < 0) { Throw.ArgumentOutOfRange(nameof(tryLength)); } if (handlerOffset < 0) { Throw.ArgumentOutOfRange(nameof(handlerOffset)); } if (handlerLength < 0) { Throw.ArgumentOutOfRange(nameof(handlerLength)); } } int catchTokenOrOffset; switch (kind) { case ExceptionRegionKind.Catch: if (!IsValidCatchTypeHandle(catchType)) { Throw.InvalidArgument_Handle(nameof(catchType)); } catchTokenOrOffset = MetadataTokens.GetToken(catchType); break; case ExceptionRegionKind.Filter: if (filterOffset < 0) { Throw.ArgumentOutOfRange(nameof(filterOffset)); } catchTokenOrOffset = filterOffset; break; case ExceptionRegionKind.Finally: case ExceptionRegionKind.Fault: catchTokenOrOffset = 0; break; default: throw new ArgumentOutOfRangeException(nameof(kind)); } AddUnchecked(kind, tryOffset, tryLength, handlerOffset, handlerLength, catchTokenOrOffset); return(this); }
internal void AddUnchecked( ExceptionRegionKind kind, int tryOffset, int tryLength, int handlerOffset, int handlerLength, int catchTokenOrOffset) { if (HasSmallFormat) { Builder.WriteUInt16((ushort)kind); Builder.WriteUInt16((ushort)tryOffset); Builder.WriteByte((byte)tryLength); Builder.WriteUInt16((ushort)handlerOffset); Builder.WriteByte((byte)handlerLength); } else { Builder.WriteInt32((int)kind); Builder.WriteInt32(tryOffset); Builder.WriteInt32(tryLength); Builder.WriteInt32(handlerOffset); Builder.WriteInt32(handlerLength); } Builder.WriteInt32(catchTokenOrOffset); }
/// <summary> /// Adds an exception clause. /// </summary> /// <param name="kind">Clause kind.</param> /// <param name="tryOffset">Try block start offset.</param> /// <param name="tryLength">Try block length.</param> /// <param name="handlerOffset">Handler start offset.</param> /// <param name="handlerLength">Handler length.</param> /// <param name="catchType"> /// <see cref="TypeDefinitionHandle"/>, <see cref="TypeReferenceHandle"/> or <see cref="TypeSpecificationHandle"/>, /// or nil if <paramref name="kind"/> is not <see cref="ExceptionRegionKind.Catch"/> /// </param> /// <param name="filterOffset"> /// Offset of the filter block, or 0 if the <paramref name="kind"/> is not <see cref="ExceptionRegionKind.Filter"/>. /// </param> /// <returns>Encoder for the next clause.</returns> /// <exception cref="ArgumentException"><paramref name="catchType"/> is invalid.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="kind"/> has invalid value.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="tryOffset"/>, <paramref name="tryLength"/>, <paramref name="handlerOffset"/> or <paramref name="handlerLength"/> is out of range. /// </exception> /// <exception cref="InvalidOperationException">Method body was not declared to have exception regions.</exception> public ExceptionRegionEncoder Add( ExceptionRegionKind kind, int tryOffset, int tryLength, int handlerOffset, int handlerLength, EntityHandle catchType = default(EntityHandle), int filterOffset = 0) { if (Builder == null) { Throw.InvalidOperation(SR.MethodHasNoExceptionRegions); } if (HasSmallFormat) { if (unchecked((ushort)tryOffset) != tryOffset) Throw.ArgumentOutOfRange(nameof(tryOffset)); if (unchecked((byte)tryLength) != tryLength) Throw.ArgumentOutOfRange(nameof(tryLength)); if (unchecked((ushort)handlerOffset) != handlerOffset) Throw.ArgumentOutOfRange(nameof(handlerOffset)); if (unchecked((byte)handlerLength) != handlerLength) Throw.ArgumentOutOfRange(nameof(handlerLength)); } else { if (tryOffset < 0) Throw.ArgumentOutOfRange(nameof(tryOffset)); if (tryLength < 0) Throw.ArgumentOutOfRange(nameof(tryLength)); if (handlerOffset < 0) Throw.ArgumentOutOfRange(nameof(handlerOffset)); if (handlerLength < 0) Throw.ArgumentOutOfRange(nameof(handlerLength)); } int catchTokenOrOffset; switch (kind) { case ExceptionRegionKind.Catch: if (!IsValidCatchTypeHandle(catchType)) { Throw.InvalidArgument_Handle(nameof(catchType)); } catchTokenOrOffset = MetadataTokens.GetToken(catchType); break; case ExceptionRegionKind.Filter: if (filterOffset < 0) { Throw.ArgumentOutOfRange(nameof(filterOffset)); } catchTokenOrOffset = filterOffset; break; case ExceptionRegionKind.Finally: case ExceptionRegionKind.Fault: catchTokenOrOffset = 0; break; default: throw new ArgumentOutOfRangeException(nameof(kind)); } AddUnchecked(kind, tryOffset, tryLength, handlerOffset, handlerLength, catchTokenOrOffset); return this; }
// Another case of System.Reflection and System.Reflection.Metadata defining the exact same enum. public static ExceptionHandlingClauseOptions ToExceptionHandlingClauseOptions(this ExceptionRegionKind kind) => (ExceptionHandlingClauseOptions)kind;
public void AddRegion( ExceptionRegionKind kind, int tryOffset, int tryLength, int handlerOffset, int handlerLength, EntityHandle catchType, int filterOffset) { if (_isSmallFormat) { Builder.WriteUInt16((ushort)kind); Builder.WriteUInt16((ushort)tryOffset); Builder.WriteByte((byte)tryLength); Builder.WriteUInt16((ushort)handlerOffset); Builder.WriteByte((byte)handlerLength); } else { Builder.WriteInt32((int)kind); Builder.WriteInt32(tryOffset); Builder.WriteInt32(tryLength); Builder.WriteInt32(handlerOffset); Builder.WriteInt32(handlerLength); } switch (kind) { case ExceptionRegionKind.Catch: Builder.WriteInt32(MetadataTokens.GetToken(catchType)); break; case ExceptionRegionKind.Filter: Builder.WriteInt32(filterOffset); break; default: Builder.WriteInt32(0); break; } }