Exemplo n.º 1
0
        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);
        }