コード例 #1
0
        public override List <ConditionPropery> Get <TSource>()
        {
            List <ConditionPropery> cps = new List <ConditionPropery>();

            Type sourceType = typeof(TSource);

            PropertyInfo[] props = sourceType.GetProperties();
            foreach (PropertyInfo prop in props)
            {
                object[] attrs = prop.GetCustomAttributes(true);
                foreach (object attr in attrs)
                {
                    ConditionAttribute conAttr = attr as ConditionAttribute;

                    if (conAttr != null)
                    {
                        ConditionPropery conProp = new ConditionPropery();
                        conProp.Key.PropertyName = prop.Name;
                        conProp.Key.PropertyType = prop.PropertyType;
                        conProp.action           = conAttr.action;
                        cps.Add(conProp);
                    }
                }
            }

            return(cps);
        }
コード例 #2
0
 public static Func <TSource, bool> GetWhereFunc(ConditionPropery conProp)
 {
     lock (lockobj)
     {
         curConProp = conProp;
     }
     return(FuncMethod);
 }
コード例 #3
0
        public ConditionProperyCollectionBuilder <TSource> AddConditionValue(string name, object value)
        {
            ConditionPropery conp = conProps.FirstOrDefault(cp => cp.Key.PropertyName == name);

            if (conp != null)
            {
                conp.PropertyValue = value;
            }

            return(this);
        }
コード例 #4
0
        public static Expression <Func <T, bool> > GetMeberEqualValueLambda <T>(ConditionPropery conProp)
        {
            var        param = Expression.Parameter(typeof(T), "p");
            Expression body  = param;

            foreach (var member in conProp.Key.PropertyName.Split('.'))
            {
                body = Expression.PropertyOrField(body, member);
            }
            var convert = Expression.Convert(body, conProp.Key.PropertyType);


            Expression constvalue = Expression.Constant(conProp.PropertyValue);
            var        equal      = Expression.Equal(convert, constvalue);

            return((Expression <Func <T, bool> >)Expression.Lambda(equal, param));
        }
コード例 #5
0
 public static Expression <Func <TSource, bool> > GetWhereExpression(ConditionPropery conProp)
 {
     return(ExpressionHelper.GetMeberEqualValueLambda <TSource>(conProp));
 }