private bool HasSmallExceptionRegions(IList <ExceptionHandlingClause> clauses) { System.Diagnostics.Debug.Assert(clauses != null); if (!ExceptionRegionEncoder.IsSmallRegionCount(clauses.Count)) { return(false); } foreach (var clause in clauses) { if (!ExceptionRegionEncoder.IsSmallExceptionRegion(clause.TryOffset, clause.TryLength) || !ExceptionRegionEncoder.IsSmallExceptionRegion(clause.HandlerOffset, clause.HandlerLength)) { return(false); } } return(true); }
private void SerializeExceptionRegions(MethodBody body) { // Get exception clauses, quit if none var clauses = body.ExceptionHandlingClauses; if (clauses.Count == 0) { return; } // Can we use a small exception table? var useSmallTable = HasSmallExceptionRegions(body.ExceptionHandlingClauses); // Align to 4 byte boundary var exre = ExceptionRegionEncoder.SerializeTableHeader(_metadata.ILBuilder, clauses.Count, useSmallTable); foreach (var ex in body.ExceptionHandlingClauses) { exre.Add((ExceptionRegionKind)ex.Flags, ex.TryOffset, ex.TryLength, ex.HandlerOffset, ex.HandlerLength, ex.Flags == ExceptionHandlingClauseOptions.Clause ? _metadata.GetTypeHandle(ex.CatchType) : default(EntityHandle), ex.Flags == ExceptionHandlingClauseOptions.Filter ? ex.FilterOffset : 0); } }