Beispiel #1
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();
        }