/// <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; }
/// <summary> /// Configures the facade with the supplied <see cref="IQueryfyConfiguration"/>. /// </summary> /// <param name="configuration">The <see cref="IQueryfyConfiguration"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="configuration"/>' cannot be null. </exception> public static void ConfigureWith([NotNull] IQueryfyConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } Kernel.Rebind <IQueryfyConfiguration>().ToConstant(configuration).InSingletonScope(); }
/// <summary> /// Initializes a new instance of the <see cref="QueryficationBuilder"/> class. /// </summary> /// <param name="configuration">The <see cref="IQueryfyConfiguration"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="configuration"/>' cannot be null. </exception> public QueryficationBuilder([NotNull] IQueryfyConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } this.configuration = configuration; }
/// <summary> /// Initializes a new instance of the <see cref="QueryficationProcessingContext"/> class. /// </summary> /// <param name="sourceValue">The source value.</param> /// <param name="configuration">The <see cref="IQueryfyConfiguration"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="sourceValue"/>' and '<paramref name="configuration"/>' cannot be null. </exception> public QueryficationProcessingContext([NotNull] Object sourceValue, [NotNull] IQueryfyConfiguration configuration) { if (sourceValue == null) { throw new ArgumentNullException(nameof(sourceValue)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } this.SourceValue = sourceValue; this.Configuration = configuration; }
/// <summary> /// Initializes a new instance of the <see cref="QueryficationResult"/> class. /// </summary> /// <param name="configuration">The <see cref="IQueryfyConfiguration"/>.</param> /// <param name="processedValues">The processed values.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="configuration"/>' and '<paramref name="processedValues"/>' cannot be null. </exception> public QueryficationResult([NotNull] IQueryfyConfiguration configuration, [NotNull] IEnumerable <KeyValuePair <String, String> > processedValues) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (processedValues == null) { throw new ArgumentNullException(nameof(processedValues)); } this.configuration = configuration; this.ProcessedValues = processedValues; this.QueryString = this.GetQueryString(); this.EncodedQueryString = this.GetQueryString(Uri.EscapeDataString); }
/// <summary> /// Initializes a new instance of the <see cref="ParserContext"/> class. /// </summary> /// <param name="query">The query to parse.</param> /// <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="valueProcessorFactory">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="query"/>', '<paramref name="configuration"/>', '<paramref name="queryficationEngine"/>', '<paramref name="valueProcessorFactory"/>', '<paramref name="lambdaExpressionInitializer"/>' and '<paramref name="instanceFactory"/>' cannot be null. </exception> public ParserContext(String query, IQueryfyConfiguration configuration, IQueryficationEngine queryficationEngine, IValueProcessorFactory valueProcessorFactory, ILambdaExpressionInitializer lambdaExpressionInitializer, IInstanceFactory instanceFactory) { if (String.IsNullOrEmpty(query)) { throw new ArgumentNullException(nameof(query)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (queryficationEngine == null) { throw new ArgumentNullException(nameof(queryficationEngine)); } if (valueProcessorFactory == null) { throw new ArgumentNullException(nameof(valueProcessorFactory)); } if (lambdaExpressionInitializer == null) { throw new ArgumentNullException(nameof(lambdaExpressionInitializer)); } if (instanceFactory == null) { throw new ArgumentNullException(nameof(instanceFactory)); } this.queryficationDictionary = QueryficationDictionary.FromQueryString(query, configuration); this.propertyParserMaps = new ParserMapCollection(); this.Configuration = configuration; this.queryficationEngine = queryficationEngine; this.InstanceFactory = instanceFactory; this.ValueProcessorFactory = valueProcessorFactory; this.lambdaExpressionInitializer = lambdaExpressionInitializer; }
/// <summary> /// Initializes a new instance of the <see cref="ParserProcessingContext"/> class. /// </summary> /// <param name="sourceValue">The source value.</param> /// <param name="destinationType">The <see cref="Type"/> of the destination.</param> /// <param name="configuration">The <see cref="IQueryfyConfiguration"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="sourceValue"/>', '<paramref name="configuration"/>' and '<paramref name="destinationType"/>' cannot be null. </exception> public ParserProcessingContext([NotNull] String sourceValue, [NotNull] Type destinationType, [NotNull] IQueryfyConfiguration configuration) { if (String.IsNullOrEmpty(sourceValue)) { throw new ArgumentNullException(nameof(sourceValue)); } if (destinationType == null) { throw new ArgumentNullException(nameof(destinationType)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } this.SourceValue = sourceValue; this.Configuration = configuration; this.DestinationType = destinationType; }
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); }