public void AssignTo(GeneratedField field) { var action = new FieldAssignmentAction(builder, this); action.To(field.Field); this.context.TypeGenerationActions.Add(action); }
public void Build() { GeneratedMethod entryPoint = null; NestedType = context.CreateNestedType(type => { var callingType = type.AddField(context.Builder, "CallingType"); var fields = new List <GeneratedField> { callingType }; for (int i = 0; i < argumentTypes.Count; i++) { fields.Add(type.AddField(argumentTypes[i], "Field" + i)); } var constructorAction = type.AddConstructor(constructor => { var constructorArguments = new Hashtable(); for (int i = 0; i < fields.Count; i++) { GeneratedField field = fields[i]; constructorArguments.Add(field, constructor.CreateArgument(() => field)); } constructor.WithBody(body => { foreach (GeneratedField field in constructorArguments.Keys) { var parameter = (GeneratedParameter)constructorArguments[field]; parameter.AssignTo(field); } }); }); Constructor = () => constructorAction.Constructor; for (int i = 0; i < methods.Count; i++) { var info = methods[i]; entryPoint = type.AddMethod(method => { method.Named(info.Name); method.Returns(returnType); method.WithBody(body => { if (info.Body != null) { info.Body(body); } if (returnType != (typeof(void))) { var variable = body.CreateVariable(returnType); if (entryPoint == null) { if (info.ExitClosure == null) { variable.AssignFrom(() => body.Call(() => info.Method().MethodBuilder().MethodBuilder, () => fields)); } else { info.ExitClosure(body, variable, info.Method, callingType); } } else { if (info.ExitClosure == null) { body.TargettingSelf(); variable.AssignFrom(() => body.Call(entryPoint, returnType)); } else { info.ExitClosure(body, variable, () => entryPoint, callingType); } } body.Return(variable); } else { if (entryPoint == null) { if (info.ExitClosure == null) { body.Call(() => info.Method().MethodBuilder().MethodBuilder, () => fields); } else { info.ExitClosure(body, null, info.Method, callingType); } } else { if (info.ExitClosure == null) { body.TargettingSelf(); body.Call(() => entryPoint, () => fields); } else { info.ExitClosure(body, null, () => entryPoint, callingType); } } body.Return(); } }); }); } }); NestedType.EntryPoint = entryPoint.MethodBuilder; }
public void AssignFrom(GeneratedField field, GeneratedField parent) { actions.Add(new FieldLoadAction(method, field.Field, parent)); actions.Add(new VariableAssignmentAction(() => method.MethodBuilder(), localIndex)); }