예제 #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);
        }