public static void Apply( MethodDefinition method, WeaveExpr @catch) { if (method.HasBody == false) { return; } //throw new ArgumentException("method does not have a body"); var ilgen = method.Body.GetILProcessor(); var head = method.GetHead(); var tail = method.GetTail(); ilgen.Emit(OpCodes.Nop); @catch(ilgen, new ILCursor(ilgen, tail)); method.Body.ExceptionHandlers.Add(new ExceptionHandler(ExceptionHandlerType.Catch) { CatchType = Net2Resolver.GetType(nameof(Exception)), TryStart = head, TryEnd = tail.Next, HandlerStart = tail.Next, HandlerEnd = method.GetTail() }); }
public static void Apply( MethodDefinition method, Func <Instruction, bool> check, WeaveExpr callback) { if (method.HasBody == false) { return; } //throw new ArgumentException("method does not have a body"); var ilgen = method.Body.GetILProcessor(); var instructionsCopy = new Instruction[method.Body.Instructions.Count]; method.Body.Instructions.CopyTo(instructionsCopy, 0); foreach (var inst in instructionsCopy) { if (check(inst)) { callback(ilgen, new ILCursor(ilgen, inst)); } } }
public static void Apply(MethodDefinition method, WeaveExpr before, WeaveExpr after) { if (method.HasBody == false) { return; } //throw new ArgumentException("method does not have a body"); var ilgen = method.Body.GetILProcessor(); before(ilgen, new ILCursor(ilgen, method.GetHead())); if (method.GetTail().Previous != null) { after(ilgen, new ILCursor(ilgen, method.GetTail().Previous)); } else { after(ilgen, new ILCursor(ilgen, true)); } }