예제 #1
0
        private void GenerateSetValuesDirect(IlBuilder processor, Func <MemberHandler, bool> cb1, Func <MemberHandler, bool> cb2)
        {
            // User u = (User)o;
            processor.DeclareLocal(_model);
            processor.LoadArg(2).Cast(_model).SetLoc(0);
            // set values
            int n = 0;

            foreach (var f in _info.Members)
            {
                if (!f.Is.DbGenerate && !f.Is.HasOne && !f.Is.HasMany && !f.Is.HasAndBelongsToMany)
                {
                    if (!cb1(f))
                    {
                        processor.LoadArg(1).LoadArg(0).LoadInt(n);
                        if (cb2(f))
                        {
                            processor.LoadInt(f.Is.Count ? 1 : 2)
                            .Call(_handler.ModelHandlerBaseTypeNewSpKeyValueDirect);
                        }
                        else
                        {
                            processor.LoadLoc(0);
                            processor.GetMember(f, _handler);
                            if (f.Is.BelongsTo)
                            {
                                processor.CallVirtual(_handler.Import(f.MemberType.GetMethod("get_ForeignKey")));
                            }
                            else if (f.Is.LazyLoad)
                            {
                                var it = f.MemberType.GetGenericArguments()[0];
                                processor.CallVirtual(_handler.Import(f.MemberType.GetMethod("get_Value")));
                                processor.Box(_handler.Import(it));
                            }
                            else
                            {
                                processor.Box(_handler.Import(f.MemberType));
                            }
                            processor.Call(_handler.ModelHandlerBaseTypeNewKeyValue);
                        }
                        processor.CallVirtual(_handler.KeyOpValueListAdd);
                    }
                    n++;
                }
            }
        }
예제 #2
0
        private void GenerateSetValuesForPartialUpdate(IlBuilder processor)
        {
            // User u = (User)o;
            processor.DeclareLocal(_model);
            processor.LoadArg(2).Cast(_model).SetLoc(0);
            // set values
            int n = 0;

            foreach (var f in _info.Members)
            {
                if (!f.Is.DbGenerate && !f.Is.HasOne && !f.Is.HasMany && !f.Is.HasAndBelongsToMany)
                {
                    if (!f.Is.Key && (f.Is.UpdatedOn || f.Is.SavedOn || !f.Is.CreatedOn || f.Is.Count))
                    {
                        if (f.Is.UpdatedOn || f.Is.SavedOn || f.Is.Count)
                        {
                            processor.LoadArg(1).LoadArg(0).LoadInt(n)
                            .LoadInt(f.Is.Count ? 1 : 2)
                            .Call(_handler.ModelHandlerBaseTypeNewSpKeyValueDirect).CallVirtual(_handler.KeyOpValueListAdd);
                        }
                        else
                        {
                            processor.LoadArg(0).LoadArg(1).LoadLoc(0).LoadString(f.Name).LoadInt(n).LoadLoc(0);
                            processor.GetMember(f, _handler);
                            if (f.Is.BelongsTo)
                            {
                                processor.CallVirtual(_handler.Import(f.MemberType.GetMethod("get_ForeignKey")));
                            }
                            else if (f.Is.LazyLoad)
                            {
                                var it = f.MemberType.GetGenericArguments()[0];
                                processor.CallVirtual(_handler.Import(f.MemberType.GetMethod("get_Value")));
                                processor.Box(_handler.Import(it));
                            }
                            else
                            {
                                processor.Box(_handler.Import(f.MemberType));
                            }
                            processor.Call(_handler.ModelHandlerBaseTypeAddKeyValue);
                        }
                    }
                    n++;
                }
            }
        }
예제 #3
0
        private void GenerateGetValue(TypeDefinition type, MemberHandler member, TypeReference memberType)
        {
            var method = new MethodDefinition("GetValue", CtMethodAttr, _handler.ObjectType);

            method.Parameters.Add(new ParameterDefinition("obj", ParameterAttributes.None, _handler.ObjectType));
            var processor = new IlBuilder(method.Body);

            processor.DeclareLocal(_handler.ObjectType);
            processor.LoadArg(1).Cast(_model);
            processor.GetMember(member, _handler);
            if (member.MemberInfo.MemberType.IsValueType)
            {
                processor.Box(memberType);
            }
            processor.SetLoc(0);
            processor.LoadLoc(0);
            processor.Return();
            processor.Append();
            type.Methods.Add(method);
        }
예제 #4
0
        private void GenerateGetKeyValuesDirect()
        {
            var method = new MethodDefinition("GetKeyValuesDirect", MethodAttr, _handler.VoidType);

            method.Overrides.Add(_handler.GetKeyValuesDirect);
            method.Parameters.Add(new ParameterDefinition("dic", ParameterAttributes.None, _handler.DictionaryStringObjectType));
            method.Parameters.Add(new ParameterDefinition("o", ParameterAttributes.None, _handler.ObjectType));
            var processor = new IlBuilder(method.Body);

            // User u = (User)o;
            processor.DeclareLocal(_model);
            processor.LoadArg(2).Cast(_model).SetLoc(0);
            // set values
            foreach (var f in _info.KeyMembers)
            {
                processor.LoadArg(1).LoadString(f.Name).LoadLoc(0);
                processor.GetMember(f, _handler);
                processor.Box(_handler.Import(f.MemberType)).CallVirtual(_handler.DictionaryStringObjectAdd);
            }

            processor.Return();
            processor.Append();
            _result.Methods.Add(method);
        }
예제 #5
0
        private void GenerateGetKeyValueDirect()
        {
            var method = new MethodDefinition("GetKeyValueDirect", MethodAttr, _handler.ObjectType);

            method.Overrides.Add(_handler.GetKeyValueDirect);
            method.Parameters.Add(new ParameterDefinition("o", ParameterAttributes.None, _handler.ObjectType));
            var processor = new IlBuilder(method.Body);

            if (_info.KeyMembers.Length == 1)
            {
                var h = _info.KeyMembers[0];
                processor.LoadArg(1).Cast(_model);
                processor.GetMember(h, _handler);
                processor.Box(_handler.Import(h.MemberType));
            }
            else
            {
                processor.LoadNull();
            }

            processor.Return();
            processor.Append();
            _result.Methods.Add(method);
        }