Beispiel #1
0
        private static string ComposeWhereClauseTemplateForShortcutAttributePath(FilterShortcutAttribute shortcutAttribute)
        {
            string whereClauseTemplate = string.Empty;

            string[] clauses       = shortcutAttribute.Path.Split("[]");
            int      argumentIndex = 0;

            for (int i = 0; i != clauses.Length; i++, argumentIndex++)
            {
                if (i != 0)
                {
                    whereClauseTemplate += $".Any(x{argumentIndex} => x{argumentIndex}";
                }

                whereClauseTemplate += clauses[i];
            }

            whereClauseTemplate += "{0}";

            for (int i = 0; i != clauses.Length - 1; i++)
            {
                whereClauseTemplate += ')';
            }

            return(whereClauseTemplate);
        }
Beispiel #2
0
        private static void CombineWhereClauseForFilter(string whereClauseTemplate, ParameterIndex parameterIndex, List <string> whereClauses, List <object> parameters, PropertyInfo property, IFilter filter)
        {
            if (whereClauseTemplate != "{0}")
            {
                whereClauseTemplate = string.Format(whereClauseTemplate, ".{0}");
            }

            FilterShortcutAttribute shortcutAttribute = property.GetCustomAttribute <FilterShortcutAttribute>();

            if (shortcutAttribute == null || string.IsNullOrEmpty(shortcutAttribute.Path))
            {
                whereClauseTemplate = string.Format(whereClauseTemplate, property.Name + "{0}");
            }

            else
            {
                whereClauseTemplate = string.Format(whereClauseTemplate, ComposeWhereClauseTemplateForShortcutAttributePath(shortcutAttribute));
            }

            CombineWhereClauses(filter, whereClauseTemplate, parameterIndex, whereClauses, parameters);
        }
Beispiel #3
0
        private static void CombineWhereClauseForValue(string whereClauseTemplate, ParameterIndex parameterIndex, List <string> whereClauses, List <object> parameters, PropertyInfo property, object value)
        {
            FilterShortcutAttribute shortcutAttribute = property.GetCustomAttribute <FilterShortcutAttribute>();

            if (shortcutAttribute != null && !string.IsNullOrEmpty(shortcutAttribute.Path))
            {
                whereClauseTemplate = string.Format(whereClauseTemplate, ComposeWhereClauseTemplateForShortcutAttributePath(shortcutAttribute));
            }

            string whereClause;

            if (property.Name == "Equals")
            {
                if (value is DateTime)
                {
                    whereClause = string.Format(whereClauseTemplate, $".Date = @{parameterIndex.Value++}");
                }

                else
                {
                    whereClause = string.Format(whereClauseTemplate, $" = @{parameterIndex.Value++}");
                }
            }

            else if (property.Name == "From")
            {
                whereClause = string.Format(whereClauseTemplate, $" >= @{parameterIndex.Value++}");
            }

            else if (property.Name == "To")
            {
                whereClause = string.Format(whereClauseTemplate, $" <= @{parameterIndex.Value++}");
            }

            else if (property.Name == "Contains")
            {
                whereClause = string.Format(whereClauseTemplate, $".Contains(@{parameterIndex.Value++})");
            }

            else
            {
                if (whereClauseTemplate != "{0}")
                {
                    whereClauseTemplate = string.Format(whereClauseTemplate, ".{0}");
                }

                whereClause = string.Format(whereClauseTemplate, $"{property.Name} = @{parameterIndex.Value++}");
            }

            whereClauses.Add(whereClause);

            if (value is DateTime && property.Name == "Equals")
            {
                parameters.Add(((DateTime)value).Date);
            }

            else
            {
                parameters.Add(value);
            }
        }
        private static string ComposeWhereClauseTemplateForShortcutAttributePath(Indexer shortcutIndexer, FilterShortcutAttribute shortcutAttribute)
        {
            StringBuilder whereClauseTemplate = new StringBuilder();

            string[] clauses = shortcutAttribute.Path.Split("[]");

            for (int i = 0; i != clauses.Length; i++)
            {
                if (i != 0)
                {
                    shortcutIndexer.Value++;
                    whereClauseTemplate.Append($".Any(x{shortcutIndexer.Value} => x{shortcutIndexer.Value}");
                }

                whereClauseTemplate.Append(clauses[i]);
            }

            whereClauseTemplate.Append("{0}");
            whereClauseTemplate.Append(new string(')', clauses.Length - 1));
            return(whereClauseTemplate.ToString());
        }