private void ProcessPropertySetCallUpdateColumn(IlBuilder processor)
 {
     processor.LoadArg(0);
     processor.LoadString(_pi.ColumnName);
     processor.Call(_handler.ColumnUpdated);
     processor.InsertBefore(_pi.PropertyDefinition.SetMethod.Body.Instructions.LastItem());
 }
Exemple #2
0
        private void ProcessGenericPropertyInConstructor(PropertyInformation pi, IlBuilder processor)
        {
            processor.LoadArg(0).LoadArg(0);
            MethodReference ci1;
            var             ft = (GenericInstanceType)pi.FieldDefinition.FieldType;

            if (pi.IsHasOne || pi.IsHasMany || pi.IsHasAndBelongsToMany)
            {
                ci1 = ft.GetConstructor(typeof(DbObjectSmartUpdate), typeof(string), typeof(string));
                var ob = GetOrderByString(pi);
                if (string.IsNullOrEmpty(ob))
                {
                    processor.LoadNull();
                }
                else
                {
                    processor.LoadString(ob);
                }
            }
            else
            {
                ci1 = ft.GetConstructor(typeof(DbObjectSmartUpdate), typeof(string));
            }
            if (pi.IsLazyLoad)
            {
                processor.LoadString(pi.ColumnName);
            }
            else
            {
                processor.Nop().Nop().Nop().Nop().LoadString(pi.FieldDefinition.Name);
            }
            var ctor = _handler.Import(ci1);

            ctor.DeclaringType = ft; //NOTE: might be a bug of Cecil
            processor.NewObj(ctor);
            processor.SetField(pi.FieldDefinition);
        }
Exemple #3
0
        private void GenerateSetValuesForSelectDirectDirect(string methodName, bool noLazy)
        {
            var method = new MethodDefinition(methodName, MethodAttr, _handler.VoidType);

            method.Overrides.Add(noLazy ? _handler.SetValuesForSelectDirectNoLazy : _handler.SetValuesForSelectDirect);
            method.Parameters.Add(new ParameterDefinition("keys", ParameterAttributes.None, _handler.ListKeyValuePairStringStringType));
            var processor = new IlBuilder(method.Body);

            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(_handler.KeyValuePairStringStringCtor);

                        processor.CallVirtual(_handler.ListKeyValuePairStringStringAdd);
                    }
                }
            }

            processor.Return();
            processor.Append();
            _result.Methods.Add(method);
        }
Exemple #4
0
        private void GenerateLoadRelationValues(bool useIndex, bool noLazy)
        {
            int    index      = _info.SimpleMembers.Length;
            string methodName = useIndex ? "LoadRelationValuesByIndex" : "LoadRelationValuesByName";

            if (noLazy)
            {
                methodName = methodName + "NoLazy";
            }
            var method = new MethodDefinition(methodName, MethodAttr, _handler.VoidType);

            method.Overrides.Add(useIndex
                ? (noLazy ? _handler.LoadRelationValuesByIndexNoLazy : _handler.LoadRelationValuesByIndex)
                : (noLazy ? _handler.LoadRelationValuesByNameNoLazy : _handler.LoadRelationValuesByName));
            method.Parameters.Add(new ParameterDefinition("o", ParameterAttributes.None, _handler.ObjectType));
            method.Parameters.Add(new ParameterDefinition("dr", ParameterAttributes.None, _handler.DataReaderInterface));
            var processor = new IlBuilder(method.Body);

            if (_info.RelationMembers.Length > 0)
            {
                // User u = (User)o;
                processor.DeclareLocal(_model);
                processor.LoadArg(1).Cast(_model).SetLoc(0);
                // set values
                foreach (var f in _info.RelationMembers)
                {
                    if (f.Is.LazyLoad)
                    {
                        if (noLazy)
                        {
                            processor.LoadLoc(0);
                            processor.GetMember(f, _handler);
                            processor.LoadArg(2);
                            if (useIndex)
                            {
                                processor.LoadInt(index++).CallVirtual(_handler.GetDataReaderMethodInt());
                            }
                            else
                            {
                                processor.LoadString(f.Name).CallVirtual(_handler.GetDataReaderMethodString());
                            }
                            processor.LoadInt(0);
                            processor.CallVirtual(_handler.LazyLoadingInterfaceWrite);
                        }
                    }
                    else if (f.Is.BelongsTo)
                    {
                        processor.LoadLoc(0);
                        processor.GetMember(f, _handler);
                        processor.LoadArg(2);
                        if (useIndex)
                        {
                            processor.LoadInt(index++).CallVirtual(_handler.GetDataReaderMethodInt());
                        }
                        else
                        {
                            processor.LoadString(f.Name).CallVirtual(_handler.GetDataReaderMethodString());
                        }
                        processor.CallVirtual(_handler.BelongsToInterfaceSetForeignKey);
                    }
                }
            }

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