Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }