Example #1
0
        public static ConditionPredicate <T> GetConditionPredicate <T>(string fieldName, ExpressionOperator expressionOperator, string value)
        {
            var        itemType     = typeof(T);
            var        predParam    = Expression.Parameter(itemType, "Target");
            var        propertyInfo = itemType.GetProperty(fieldName);
            Expression left         = Expression.Property(predParam, propertyInfo);
            Expression right        = Expression.Constant(ObjectTypeConverter.ChangeType(value, propertyInfo.PropertyType), propertyInfo.PropertyType);
            var        result       = GetExpression(expressionOperator, left, right);
            var        function     = (Func <T, bool>)Expression.Lambda(result, predParam).Compile();

            return(new ConditionPredicate <T>(function));
        }
Example #2
0
        public static Delegate GetActionPredicate <T>(string fieldName, ExpressionOperator expressionOperator, string value)
        {
            var        itemType            = typeof(T);
            var        parameterExpression = Expression.Parameter(itemType, "Target");
            var        propertyInfo        = itemType.GetProperty(fieldName);
            Expression left     = Expression.Property(parameterExpression, propertyInfo);
            Expression right    = Expression.Constant(ObjectTypeConverter.ChangeType(value, propertyInfo.PropertyType), propertyInfo.PropertyType);
            var        result   = GetExpression(expressionOperator, left, right);
            var        function = Expression.Lambda(result, parameterExpression).Compile();

            return(function);
        }