Esempio n. 1
0
        private void GenerateCreateInstance()
        {
            var ctor   = _model.GetConstructor(noArgs);
            var method = _result.DefineMethod("CreateInstance", CtMethodAttr, objectType, noArgs);

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

            processor.NewObj(ctor);
            processor.Return();
        }
Esempio n. 2
0
        private void GenerateNewMember(MemberHandler pi, ILBuilder processor)
        {
            processor.LoadArg(1);
            ConstructorInfo ci1;
            var             ft = pi.MemberType;

            if (pi.Is.HasOne || pi.Is.HasMany || pi.Is.HasAndBelongsToMany)
            {
                ci1 = ft.GetConstructor(new Type[] {
                    typeof(DbObjectSmartUpdate),
                    typeof(string),
                    typeof(string)
                });
                if (string.IsNullOrEmpty(pi.OrderByString))
                {
                    processor.LoadString("Id");
                }
                else
                {
                    processor.LoadString(pi.OrderByString);
                }
            }
            else
            {
                ci1 = ft.GetConstructor(new Type[] {
                    typeof(DbObjectSmartUpdate),
                    typeof(string)
                });
            }
            if (pi.Is.HasOne || pi.Is.HasMany)
            {
                processor.LoadString(GetBelongsToColumnName(pi));
            }
            else if (pi.Is.HasAndBelongsToMany)
            {
                processor.LoadString(GetHasManyAndBelongsToColumnName(pi));
            }
            else
            {
                processor.LoadString(pi.Name);
            }
            processor.NewObj(ci1);
        }
Esempio n. 3
0
        private void GenerateSetValuesForSelectDirectDirect(bool noLazy)
        {
            var methodName = noLazy ? "SetValuesForSelectDirectNoLazy" : "SetValuesForSelectDirect";
            var method     = _result.DefineMethod(methodName, MethodAttr,
                                                  null, new Type[] { listKeyValuePairStringStringType });

            _result.DefineMethodOverride(method, noLazy
                ? handlerBaseSetValuesForSelectDirectNoLazy
                : handlerBaseSetValuesForSelectDirect);
            var processor = new ILBuilder(method.GetILGenerator());

            foreach (var f in _info.Members)
            {
                if (!f.Is.HasOne && !f.Is.HasMany && !f.Is.HasAndBelongsToMany)
                {
                    if (noLazy || !f.Is.LazyLoad)
                    {
                        processor.LoadArg(1);

                        processor.LoadString(f.Name);
                        if (f.Name != f.MemberInfo.Name)
                        {
                            processor.LoadString(f.MemberInfo.Name);
                        }
                        else
                        {
                            processor.LoadNull();
                        }
                        processor.NewObj(keyValuePairStringStringCtor);

                        processor.CallVirtual(listKeyValuePairStringStringAdd);
                    }
                }
            }

            processor.Return();
        }