예제 #1
0
        /// <summary>
        /// Validates the passed result for fitting the query
        /// </summary>
        /// <param name="result">the result to be validated with this query</param>
        /// <returns>a value indicating whether this result matches the provided query</returns>
        public bool Validate(DynamicResult result)
        {
            bool retVal = Validate(result, column);

            foreach (Where w in subWheres)
            {
                if (w.whereMode == WhereMode.And)
                {
                    if (retVal)
                    {
                        retVal &= w.Validate(result);
                    }
                }
                else
                {
                    if (!retVal)
                    {
                        retVal |= w.Validate(result);
                    }
                }
            }

            return(retVal);
        }
예제 #2
0
        /// <summary>
        /// Validates a Dynamic Result against a DataColumn
        /// </summary>
        /// <param name="result">the result to check</param>
        /// <param name="column">the column to check against it</param>
        /// <returns>a value indicating whether the provided result matches the query in the column</returns>
        private static bool Validate(DynamicResult result, Column column)
        {
            dynamic d = result[column.ColumnName];

            if (d == null && column.Value == null && column.ComparisonMode == ComparisonMode.Equal)
            {
                return(true);
            }
            if (d == null && column.Value != null && column.ComparisonMode == ComparisonMode.NotEqual)
            {
                return(true);
            }
            if (d == null)
            {
                return(false);
            }

            switch (column.ComparisonMode)
            {
            case ComparisonMode.Equal:
            {
                return((d is string) ? d.Equals(column.Value, StringComparison.OrdinalIgnoreCase) : d.Equals(column.Value));
            }

            case ComparisonMode.NotEqual:
            {
                return(d != column.Value);
            }

            case ComparisonMode.GreaterThan:
            {
                return(d > column.Value);
            }

            case ComparisonMode.SmallerThan:
            {
                return(d < column.Value);
            }

            case ComparisonMode.GreaterThanOrEqual:
            {
                return(d >= column.Value);
            }

            case ComparisonMode.SmallerThanOrEqual:
            {
                return(d <= column.Value);
            }

            case ComparisonMode.Between:
            {
                return(d >= column.Value && d <= column.Value2);
            }

            case ComparisonMode.Like:
            {
                return(ValidateRx(d, column.Value));
            }

            case ComparisonMode.NotLike:
            {
                return(!ValidateRx(d, column.Value));
            }
            }

            return(false);
        }