Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QueryficationContext"/> class.
        /// </summary>
        /// <param name="configuration">An implementation of the <see cref="IQueryfyConfiguration"/> interface.</param>
        /// <param name="queryficationEngine">An implementation of the <see cref="IQueryficationEngine"/> interface.</param>
        /// <param name="urlValueProcessorFactory">An implementation of the <see cref="IValueProcessorFactory"/> interface.</param>
        /// <param name="lambdaExpressionInitializer">An implementation of the <see cref="ILambdaExpressionInitializer"/> interface.</param>
        /// <param name="instanceFactory">An implementation of the <see cref="IInstanceFactory"/> interface</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="configuration"/>', '<paramref name="instanceFactory"/>', '<paramref name="lambdaExpressionInitializer"/>', '<paramref name="queryficationEngine"/>' and '<paramref name="urlValueProcessorFactory"/>' cannot be null. </exception>
        public QueryficationContext([NotNull] IQueryfyConfiguration configuration, [NotNull] IQueryficationEngine queryficationEngine, [NotNull] IValueProcessorFactory urlValueProcessorFactory, [NotNull] ILambdaExpressionInitializer lambdaExpressionInitializer, [NotNull] IInstanceFactory instanceFactory)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

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

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

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

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

            this.queryficationDictionary     = new QueryficationDictionary();
            this.Configuration               = configuration;
            this.ValueProcessorFactory       = urlValueProcessorFactory;
            this.lambdaExpressionInitializer = lambdaExpressionInitializer;
            this.queryficationEngine         = queryficationEngine;
            this.InstanceFactory             = instanceFactory;
        }
        public static QueryficationDictionary FromQueryString([NotNull] String query, [NotNull] IQueryfyConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var result  = new QueryficationDictionary(query);
            var matches = Regex.Matches(query, configuration.QueryParameterRegexPattern, RegexOptions.Singleline);

            foreach (var parameterGroup in matches.AsEnumerable().GroupBy(match => match.Groups[1].Value))
            {
                var concatenatedValues = parameterGroup.Aggregate(new StringBuilder(), (seed, current) => seed.Append(current.Groups[3].Value + "+"), seed => seed.ToString());
                concatenatedValues = concatenatedValues.Remove(concatenatedValues.Length - 1, 1);
                result.Add(parameterGroup.Key, new QueryParameter(parameterGroup.Key, concatenatedValues));
            }

            return(result);
        }