Example #1
0
        /// <summary>
        /// Generates an OData filter from a specified Linq expression.
        /// </summary>
        /// <typeparam name="T">Filter type.</typeparam>
        /// <param name="filter">Entity to use for filter generation.</param>
        /// <returns></returns>
        public static string Generate <T>(Expression <Func <T, bool> > filter)
        {
            UrlExpressionVisitor visitor = new UrlExpressionVisitor();

            visitor.Visit(filter);
            return(visitor.ToString());
        }
        /// <summary>
        /// Generates an OData filter from a specified Linq expression.
        /// </summary>
        /// <typeparam name="T">Filter type.</typeparam>
        /// <param name="filter">Entity to use for filter generation.</param>
        /// <param name="skipNullFilterParameters">Value indicating whether null values should be skipped.</param>
        /// <returns></returns>
        public static string Generate <T>(Expression <Func <T, bool> > filter, bool skipNullFilterParameters)
        {
            if (filter == null || !filter.Parameters.Any())
            {
                return(string.Empty);
            }
            var visitor = new UrlExpressionVisitor(filter.Parameters.First(), skipNullFilterParameters);

            visitor.Visit(filter);
            return(visitor.ToString());
        }