コード例 #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);
        }
コード例 #2
0
        private void GenerateSetKeyValueDirect()
        {
            var method = _result.DefineMethod("SetKeyValueDirect", MethodAttr,
                                              null, new Type[] { objectType, objectType });

            _result.DefineMethodOverride(method, handlerBaseSetKeyValueDirect);
            var processor = new ILBuilder(method.GetILGenerator());

            if (_info.KeyMembers.Length == 1)
            {
                var h = _info.KeyMembers[0];
                processor.LoadArg(1).Cast(_model);
                processor.LoadArg(2);
                var fh = _info.KeyMembers[0];
                if (fh.MemberType == typeof(long))
                {
                    processor.Call(convertToInt64);
                }
                else if (fh.MemberType == typeof(int))
                {
                    processor.Call(convertToInt32);
                }
                else if (fh.MemberType == typeof(Guid))
                {
                    processor.Unbox(h.MemberType);
                }
                else
                {
                    processor.Cast(h.MemberType);
                }
                processor.SetMember(h);
            }

            processor.Return();
        }