private static Expression <Func <TModel, bool> > ToStringValueExpression <TModel>(FilterItemModel filterItem)
            where TModel : class
        {
            if (string.IsNullOrWhiteSpace(filterItem.Value.ToString()))
            {
                throw new ArgumentException($"{filterItem.Value} is not of type {typeof(string)}.");
            }

            var filterValue = filterItem.Value.ToString();

            var entityParamSelector = ReflectionHelper.MemberSelector <TModel, string>(filterItem.Column);

            if (filterItem.Filter == FilterType.In)
            {
                var result = filterItem.CollectionExpression(entityParamSelector, x => x.ToString());
                if (result != null)
                {
                    return(result);
                }
            }

            var expression = FilterExpressionHelper.GetExpression(filterItem.Filter, filterValue);

            return(entityParamSelector.CombineSelectorParamExpression(expression));
        }
        private static Expression <Func <TModel, bool> > ToBoolValueExpression <TModel>(FilterItemModel filterItem, bool isNullable)
            where TModel : class
        {
            var nullableFilterValue = BoolHelper.ToBoolOrNull(filterItem.Value);

            if (!nullableFilterValue.HasValue)
            {
                throw new ArgumentException($"{filterItem.Value} is not of type {typeof(bool)}.");
            }

            var filterValue = nullableFilterValue.Value;

            if (isNullable)
            {
                var entityParamSelector = ReflectionHelper.MemberSelector <TModel, bool?>(filterItem.Column);
                var expression          = FilterExpressionHelper.GetNullableExpression(filterItem.Filter, filterValue);

                return(entityParamSelector.CombineSelectorParamExpression(expression));
            }
            else
            {
                var entityParamSelector = ReflectionHelper.MemberSelector <TModel, bool>(filterItem.Column);
                var expression          = FilterExpressionHelper.GetExpression(filterItem.Filter, filterValue);

                return(entityParamSelector.CombineSelectorParamExpression(expression));
            }
        }
        private static Expression <Func <TModel, bool> > ToIntValueExpression <TModel>(FilterItemModel filterItem, bool isNullable)
            where TModel : class
        {
            var type = ReflectionHelper.GetPropertyType <TModel>(filterItem.Column);

            if (type.IsEnum || type.IsNullableEnum())
            {
                if (filterItem.Filter == FilterType.Equal)
                {
                    return(EnumToExpression <TModel>(filterItem, type));
                }

                throw new ArgumentException($"Filter {filterItem.Filter} not supported for type Enum. Only {FilterType.Equal} kan be evaluated.", nameof(filterItem));
            }

            var nullableFilterValue = IntHelper.ToIntOrNull(filterItem.Value);

            if (!nullableFilterValue.HasValue)
            {
                throw new ArgumentException($"{filterItem.Value} is not of type {typeof(int)}.");
            }

            var filterValue = nullableFilterValue.Value;

            if (isNullable)
            {
                var entityParamSelector = ReflectionHelper.MemberSelector <TModel, int?>(filterItem.Column);

                if (filterItem.Filter == FilterType.In)
                {
                    var result = filterItem.CollectionExpression(entityParamSelector, IntHelper.ToIntOrNull);
                    if (result != null)
                    {
                        return(result);
                    }
                }

                var expression = FilterExpressionHelper.GetNullableExpression(filterItem.Filter, filterValue);

                return(entityParamSelector.CombineSelectorParamExpression(expression));
            }
            else
            {
                var entityParamSelector = ReflectionHelper.MemberSelector <TModel, int>(filterItem.Column);

                if (filterItem.Filter == FilterType.In)
                {
                    var result = filterItem.CollectionExpression(entityParamSelector, IntHelper.ToInt);
                    if (result != null)
                    {
                        return(result);
                    }
                }

                var expression = FilterExpressionHelper.GetExpression(filterItem.Filter, filterValue);

                return(entityParamSelector.CombineSelectorParamExpression(expression));
            }
        }
        private static Expression <Func <TModel, bool> > ToGuidValueExpression <TModel>(FilterItemModel filterItem, bool isNullable)
            where TModel : class
        {
            var nullableFilterValue = GuidHelper.ToGuidOrNull(filterItem.Value);

            if (!nullableFilterValue.HasValue || GuidHelper.GuidIsNullOrEmpty(nullableFilterValue))
            {
                throw new ArgumentException($"{filterItem.Value} is not of type {typeof(Guid)}.");
            }

            var filterValue = nullableFilterValue.Value;

            if (isNullable)
            {
                var entityParamSelector = ReflectionHelper.MemberSelector <TModel, Guid?>(filterItem.Column);

                if (filterItem.Filter == FilterType.In)
                {
                    var result = filterItem.CollectionExpression(entityParamSelector, GuidHelper.ToGuidOrNull);
                    if (result != null)
                    {
                        return(result);
                    }
                }

                var expression = FilterExpressionHelper.GetNullableExpression(filterItem.Filter, filterValue);

                return(entityParamSelector.CombineSelectorParamExpression(expression));
            }
            else
            {
                var entityParamSelector = ReflectionHelper.MemberSelector <TModel, Guid>(filterItem.Column);

                if (filterItem.Filter == FilterType.In)
                {
                    var result = filterItem.CollectionExpression(entityParamSelector, GuidHelper.ToGuid);
                    if (result != null)
                    {
                        return(result);
                    }
                }

                var expression = FilterExpressionHelper.GetExpression(filterItem.Filter, filterValue);

                return(entityParamSelector.CombineSelectorParamExpression(expression));
            }
        }