internal MethodMemento CreateMethodMemento(MethodDefinition method) { YeetIfNull(method, nameof(method)); YeetIfAbstract(method); var body = method.Body; var memento = new MethodMemento( variables: new List <VariableDefinition>(body.Variables), exceptionHandlers: new List <ExceptionHandler>(body.ExceptionHandlers), instructions: new List <Instruction>(body.Instructions), initLocals: body.InitLocals ); return(memento); }
private void EmitSetHelperMethodBody(MethodDefinition setHelperMethod, MethodMemento memento) { var targetMethodBody = setHelperMethod.Body; var ilProcessor = targetMethodBody.GetILProcessor(); foreach (var variable in memento.Variables) { targetMethodBody.Variables.Add(variable); } foreach (var handler in memento.ExceptionHandlers) { targetMethodBody.ExceptionHandlers.Add(handler); } targetMethodBody.InitLocals = memento.InitLocals; foreach (var instruction in memento.Instructions) { ilProcessor.Append(instruction); } }
internal MethodDefinition EmitSetHelper(string targetSetHelperMethodName, MethodDefinition setMethod, MethodMemento memento) { YeetIfEmptyOrNull(targetSetHelperMethodName, nameof(targetSetHelperMethodName)); YeetIfNull(setMethod, nameof(setMethod)); YeetIfNull(memento, nameof(memento)); YeetIfAbstract(setMethod); var setHelper = EmitSetHelper(targetSetHelperMethodName, setMethod); EmitSetHelperMethodBody(setHelper, memento); return(setHelper); }