예제 #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="property">The property name.</param>
        /// <param name="operation">The <see cref="Operation"/>.</param>
        /// <param name="value">The value.</param>
        /// <param name="value2">the value2</param>
        /// <param name="operationLogical">The <see cref="Enums.OperationLogical"/>.</param>
        public FilterStatement(string property, Operation operation, TPropertyType value, TPropertyType value2, OperationLogical operationLogical = OperationLogical.And)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            if (!typeof(TPropertyType).GetOperationTypes().Contains(operation))
            {
                throw new InvalidOperationException(Operation.ToString());
            }

            this.Property  = property;
            this.Operation = operation;

            if (typeof(TPropertyType).IsArray)
            {
                if (operation != Operation.Contains && operation != Operation.In)
                {
                    throw new ArgumentException("Only 'Operation.Contains' and 'Operation.In' support arrays as parameters.");
                }

                var type        = typeof(List <>);
                var genericType = type.MakeGenericType(typeof(TPropertyType).GetElementType());

                this.Value = value != null?Activator.CreateInstance(genericType, value) : null;

                this.Value2 = value2 != null?Activator.CreateInstance(genericType, value2) : null;
            }
            else
            {
                this.Value  = value;
                this.Value2 = value2;
            }

            this.OperationLogical = operationLogical;
        }
예제 #2
0
파일: Filter.cs 프로젝트: TheSpy/Nano
        /// <summary>
        /// Add <see cref="Operation.Equal"/> filter.
        /// </summary>
        /// <typeparam name="TPropertyType">The type of the property.</typeparam>
        /// <param name="property">The property name.</param>
        /// <param name="value">The value.</param>
        /// <param name="logical">The <see cref="OperationLogical"/>.</param>
        public virtual void Equal <TPropertyType>(string property, TPropertyType value, OperationLogical logical = OperationLogical.And)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            this.By(property, Operation.Equal, value, default, logical);
예제 #3
0
        private Expression GetCombinedExpression(Expression expression1, Expression expression2, OperationLogical connector)
        {
            if (expression1 == null)
            {
                throw new ArgumentNullException(nameof(expression1));
            }

            if (expression2 == null)
            {
                throw new ArgumentNullException(nameof(expression2));
            }

            return(connector == OperationLogical.And
                ? Expression.AndAlso(expression1, expression2)
                : Expression.OrElse(expression1, expression2));
        }