private void DefineMethod() { var methodName = string.Format("<{0}>b__1", _methodInfo.Name); var methodBuilder = TypeBuilder.DefineMethod(methodName, MethodAttribute); methodBuilder.InitLocals = true; methodBuilder.SetParameters(new[] { _serviceType }); methodBuilder.SetReturnType(typeof(void)); var il = new MethodWrapper(methodBuilder); if (HasReturnType()) { il.LoadThis(); } il.LoadArgument(1); foreach (var parameter in _methodInfo.GetParameters()) { LoadParameter(il, parameter); } il.CallVirtualMethod(_methodInfo); if (HasReturnType()) { il.StoreToField(ResultField); } il.DoNothing(); il.Return(); Method = methodBuilder; }
private void LoadParameter(MethodWrapper il, ParameterInfo parameter) { var field = GetFieldForParameter(parameter); il.LoadThis(); il.LoadField(field); }