コード例 #1
0
        public object UI2Row(NameValueCollection collection, Type type)
        {
            var row = Activator.CreateInstance(type, null);

            PropertyInfo[] propertyList = type.GetProperties();
            foreach (PropertyInfo pro in propertyList)
            {
                if (PropertyHelper.IsVirtual(pro))
                {
                    if (PropertyHelper.HasElement(pro))
                    {
                        var subRow = UI2Row(collection, pro.PropertyType);
                        pro.SetValue(row, subRow);
                    }
                }
                else if (collection.AllKeys.Contains(pro.Name))
                {
                    // tsuper
                    var super = PropertyHelper.GetTFieldValueRaw(pro, TF.super);
                    if (super != null && m_super > (TS)super)
                    {
                        continue;
                    }

                    object val = collection[pro.Name];

                    // refer
                    var refer = PropertyHelper.GetTFieldValue(pro, TF.refer);
                    if (refer != null)
                    {
                        val = collection.AllKeys.Contains(refer) ? collection[refer] : "";
                    }

                    // parse
                    var parse = PropertyHelper.GetTFieldValue(pro, TF.parse);
                    if (parse != null)
                    {
                        val = JMethod.Run <THelper>(parse, new object[] { val });
                    }

                    THelper.ConvertToType(pro.PropertyType, ref val);
                    pro.SetValue(row, val);
                }
            }
            return(row);
        }
コード例 #2
0
        public TListLogic <T> TWhere(string key, object value, string operate = op.eq)
        {
            while (true)
            {
                // check key input
                if (string.IsNullOrWhiteSpace(key))
                {
                    break;
                }

                // check key property
                PropertyInfo property = TType.GetProperty(key);
                if (property == null)
                {
                    break;
                }

                // convert type
                if (value.GetType() != property.PropertyType)
                {
                    THelper.ConvertToType(property.PropertyType, ref value);
                }

                ParameterExpression parameter = Expression.Parameter(TType);
                Expression          left      = Expression.Property(parameter, property);
                Expression          right     = Expression.Constant(value);
                if (value.GetType() != property.PropertyType)
                {
                    right = Expression.Convert(right, property.PropertyType);
                }

                Expression condition = null;
                switch (operate)
                {
                case op.gt:
                    condition = Expression.GreaterThan(left, right);
                    break;

                case op.gte:
                    condition = Expression.GreaterThanOrEqual(left, right);
                    break;

                case op.lt:
                    condition = Expression.LessThan(left, right);
                    break;

                case op.lte:
                    condition = Expression.LessThanOrEqual(left, right);
                    break;

                case op.like:
                    Type stringType = typeof(string);
                    condition = Expression.Call(
                        left,
                        stringType.GetMethod("Contains", new Type[] { stringType }),
                        right);
                    break;

                case op.eq:
                default:
                    condition = Expression.Equal(left, right);
                    break;
                }

                LambdaExpression lambda = Expression.Lambda(condition, parameter);
                m_query = Expression.Call(
                    typeof(Queryable),
                    "Where",
                    new Type[] { TType },
                    m_query,
                    lambda
                    );

                break;
            }
            return(this);
        }