private void GenerateNewMemberWithPrivateSetter(MemberHandler pi, ILBuilder processor, ILBuilder ctorBuilder) { var dt = typeof(Action <,>).MakeGenericType(_model, pi.MemberType); var df = _result.DefineField("$" + pi.MemberInfo.Name, dt, fieldFlag); ctorBuilder.LoadArg(0); ctorBuilder.LoadToken(dt); ctorBuilder.Call(getTypeFromHandle); ctorBuilder.LoadLoc(0); ctorBuilder.LoadString(pi.MemberInfo.Name); ctorBuilder.CallVirtual(getProperty); ctorBuilder.LoadInt(1); ctorBuilder.CallVirtual(getSetMethod); ctorBuilder.Call(createDelegate); ctorBuilder.Cast(dt); ctorBuilder.SetField(df); processor.LoadArg(0); processor.LoadField(df); processor.LoadArg(1); GenerateNewMember(pi, processor); var invoke = dt.GetMethod("Invoke"); processor.CallVirtual(invoke); }
private void GenerateCtorInit(ILBuilder ctorBuilder) { var method = _result.DefineMethod("CtorInit", CtMethodAttr, null, dbObjectSmartUpdateArgs); _result.DefineMethodOverride(method, handlerBaseCtorInit); var processor = new ILBuilder(method.GetILGenerator()); foreach (var f in _info.Members) { if (!(f.Is.RelationField || f.Is.LazyLoad)) { continue; } if (f.MemberInfo.IsProperty) { var pi = (PropertyInfo)f.MemberInfo.GetMemberInfo(); var setter = pi.GetSetMethod(true); if (setter.IsPrivate) { GenerateNewMemberWithPrivateSetter(f, processor, ctorBuilder); } else { processor.LoadArg(1); GenerateNewMember(f, processor); processor.CallVirtual(setter); } } else { processor.LoadArg(1); GenerateNewMember(f, processor); processor.SetField((FieldInfo)f.MemberInfo.GetMemberInfo()); } } processor.Return(); }