public ITypeProcessor GetCollectionProcessorFor(string collectionKind, string dataTypeName, string value) { //Console.WriteLine($"*** GetCollectionProcessorFor(<{collectionKind}>, <{dataTypeName}>, <{(value == null ? "NULL" : value)}>)"); if (string.IsNullOrEmpty(collectionKind)) { return(GetCollectionProcessorFor(dataTypeName, value)); } if (string.IsNullOrEmpty(dataTypeName)) { return(GetCollectionProcessorForValue(collectionKind, value)); } IValueProcessor elementProcessor = GetProcessorForDataType(dataTypeName) as IValueProcessor; if (elementProcessor == null) { ThrowMissingTypeName(dataTypeName); } ITypeProcessor processor = GetCollectionProcessorFor(collectionKind, elementProcessor); if (value != null) { processor.SetValue(value); } return(processor); }
public ComparisonReducer(IComparisonProcessor comparisonProcessor, IPropertyProcessor propertyProcessor, IValueProcessor valueProcessor, INotNullExpressionProcessor notNullExpressionProcessor) { this.comparisonProcessor = comparisonProcessor; this.propertyProcessor = propertyProcessor; this.valueProcessor = valueProcessor; this.notNullExpressionProcessor = notNullExpressionProcessor; }
/// <summary> /// Initializes a new instance of the <see cref="EnumerableValueProcessor"/> class. /// </summary> /// <param name="itemValueProcessor">An implementation of the <see cref="IValueProcessor"/> interface.</param> /// <exception cref="ArgumentNullException">The value of 'itemValueProcessor' cannot be null. </exception> public EnumerableValueProcessor([NotNull] IValueProcessor itemValueProcessor) { if (itemValueProcessor == null) { throw new ArgumentNullException(nameof(itemValueProcessor)); } this.itemValueProcessor = itemValueProcessor; }
public ITypeProcessor GetCollectionProcessorForValue(string collectionKind, string value) { List <string> values = value.ToStringsList(); IValueProcessor elementProcessor = _processors.FirstOrDefault(p => values.All(p.CanParse)); var collectionProcessor = GetCollectionProcessorFor(collectionKind, elementProcessor) as ICollectionProcessor; collectionProcessor?.SetValue(values); return(collectionProcessor); }
/// <summary> /// Initializes a new instance of the <see cref="LazyValueProcessor"/> class. /// </summary> /// <param name="innerValueProcessor">An implementation of the <see cref="IValueProcessor"/> interface.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="innerValueProcessor"/>' cannot be null. </exception> public LazyValueProcessor([NotNull] IValueProcessor innerValueProcessor) { if (innerValueProcessor == null) { throw new ArgumentNullException(nameof(innerValueProcessor)); } this.innerValueProcessor = innerValueProcessor; }
/// <summary> /// Sets the supplied <see cref="IValueProcessor"/>. /// </summary> /// <param name="valueProcessor">The <see cref="IValueProcessor"/>.</param> /// <returns>Returns self.</returns> /// <exception cref="ArgumentNullException">The value of '<paramref name="valueProcessor"/>' cannot be null. </exception> public IFluentQueryParameter ProcessUsing(IValueProcessor valueProcessor) { if (valueProcessor == null) { throw new ArgumentNullException(nameof(valueProcessor)); } this.valueProcessor = valueProcessor; return(this); }
public static void AddValueProcessor(this SpecFlowContext context, IValueProcessor processor) { AddDefaultValueProcessors(context); Dictionary <string, IValueProcessor> lookup = GetValueProcessorLookup(context); Dictionary <Type, IValueProcessor> typeLookup = GetValueProcessorTypeLookup(context); List <IValueProcessor> order = GetValueProcessorOrder(context); processor.DataTypeNames.ForEach(n => lookup[n] = processor); typeLookup[processor.DataType] = processor; order.Insert(0, processor); }
public CollectionProcessor(IValueProcessor elementProcessor, SpecFlowContext context, string friendlyTypeName) : base(context, friendlyTypeName) { ElementProcessor = elementProcessor; if (ElementProcessor?.DataType != typeof(TElement)) { throw new ArgumentException( $"{nameof(elementProcessor)} cannot be null and must be an {nameof(IValueProcessor)} with {nameof(DataType)} {DataType.Name}.", nameof(elementProcessor)); } }
public ICollectionProcessor Create(Type existingType) { Type elementType = GetElementType(existingType); if (elementType == null) { return(null); } IValueProcessor elementProcessor = Context.GetValueProcessor(elementType); return(Create(elementProcessor)); }
/// <summary> /// Maps the <see cref="IValueProcessor"/> to the <see cref="Type"/>. /// </summary> /// <param name="type">The <see cref="Type"/>.</param> /// <param name="valueProcessor">The <see cref="IValueProcessor"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="type"/>' and '<paramref name="valueProcessor"/>' cannot be null. </exception> public void SetRegistration(Type type, IValueProcessor valueProcessor) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (type == null) { throw new ArgumentNullException(nameof(valueProcessor)); } this.registrations[type] = valueProcessor; }
/// <summary> /// Lookup the mapped <see cref="IValueProcessor"/> for the supplied <see cref="Type"/>. /// </summary> /// <param name="type">The <see cref="Type"/> for which the mapped instance should be returned.</param> /// <param name="result"></param> /// <returns><c>true</c> if the mapping was found; otherwise, <c>false</c>.</returns> /// <exception cref="ArgumentNullException">The value of '<paramref name="type"/>' cannot be null. </exception> public Boolean TryLookup(Type type, out IValueProcessor result) { if (type == null) { throw new ArgumentNullException(nameof(type)); } foreach (var registeredType in this.registrations.OrderBy(p => p.Key.IsGenericType).ThenBy(p => p.Key.IsGenericTypeDefinition)) { if (this.CanHandle(registeredType.Key, type)) { result = registeredType.Value; return(true); } } result = null; return(false); }
public ITypeProcessor GetCollectionProcessorFor(string collectionKind, IValueProcessor processor) { if (processor == null) { return(null); } CollectionProcessorFactory factory = !string.IsNullOrEmpty(collectionKind) ? _context.GetCollectionProcessorFactory(collectionKind) : _context.GetDefaultCollectionProcessorFactory(); //Console.WriteLine($"***** Got processor factory: {factory?.GetType().Name}"); if (factory == null) { throw new Exception($"No registered CollectionProcessor for: {collectionKind}."); } return(factory.Create(processor)); }
public ITypeProcessor GetCollectionProcessorFor(string dataTypeName, string value) { if (string.IsNullOrEmpty(dataTypeName)) { return(GetCollectionProcessorForValue(null, value)); } IValueProcessor elementProcessor = GetProcessorForDataType(dataTypeName) as IValueProcessor; if (elementProcessor == null) { ThrowMissingTypeName(dataTypeName); } ITypeProcessor processor = GetCollectionProcessorFor(null, elementProcessor); if (value != null) { processor.SetValue(value); } return(processor); }
public CustomListProcessor(IValueProcessor elementProcessor, SpecFlowContext context) : base(elementProcessor, context, $"{nameof(CustomListProcessor<T>)}<{elementProcessor?.FriendlyTypeName}>") { }
/// <summary> /// Adds a new <see cref="QueryParameter"/>. /// </summary> /// <param name="parameterName">The name of the parameter.</param> /// <param name="value">The value of the parameter.</param> /// <param name="valueProcessor">The used <see cref="IValueProcessor"/></param> /// <exception cref="PropertyMustBeSpecifiedException">The property 'TypeOfValue', 'ParameterName' and 'ValueProcessor' cannot be null.</exception> /// <exception cref="ValueProcessorCannotHandleTypeException">The <see cref="IValueProcessor"/> can not handle the <see cref="Type"/> specified in the TypeOfValue property.</exception> public void AddParameter(String parameterName, Object value, IValueProcessor valueProcessor) { this.AddParameter(new QueryParameter(parameterName, value, valueProcessor)); }
/// <summary> /// Adds a new mapping for the supplied <see cref="Expression{Func{T, TProperty}}"/>. /// </summary> /// <typeparam name="T">The <see cref="Type"/>.</typeparam> /// <typeparam name="TProperty">The <see cref="Type"/> of the property.</typeparam> /// <param name="parserContext">The <see cref="IParserContext"/>.</param> /// <param name="source">The source object on which the <see cref="Expression{Func{T, TProperty}}"/> operates.</param> /// <param name="propertySelector">A <see cref="Expression"/> which selects the property which is used for the mapping.</param> /// <param name="parameterName">The parameter name which identifies the parameter in the query string.</param> /// <param name="valueProcessor">An instance of the <see cref="IValueProcessor"/> class.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="parserContext"/>', '<paramref name="source"/>', '<paramref name="propertySelector"/>', '<paramref name="parameterName"/>' and '<paramref name="valueProcessor"/>' cannot be null. </exception> public static void AddPropertyMapping <T, TProperty>([NotNull] this IParserContext parserContext, T source, [NotNull] Expression <Func <T, TProperty> > propertySelector, [NotNull] String parameterName, [NotNull] IValueProcessor valueProcessor) { if (parserContext == null) { throw new ArgumentNullException(nameof(parserContext)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } if (propertySelector == null) { throw new ArgumentNullException(nameof(propertySelector)); } if (String.IsNullOrEmpty(parameterName)) { throw new ArgumentNullException(nameof(parameterName)); } if (valueProcessor == null) { throw new ArgumentNullException(nameof(valueProcessor)); } parserContext.AddPropertyMapping(source, propertySelector, parameterName, valueProcessor); }
protected abstract ICollectionProcessor CreateCore(IValueProcessor elementProcessor);
public ArrayProcessor(IValueProcessor elementProcessor, SpecFlowContext context) : base(elementProcessor, context, $"{elementProcessor?.FriendlyTypeName}[]") { }
public ICollectionProcessor Create(IValueProcessor elementProcessor) => CreateCore(elementProcessor);
/// <summary> /// Initializes a new instance of the <see cref="ValueProcessorCannotHandleTypeException"/> class. /// </summary> /// <param name="valueProcessor">The <see cref="IValueProcessor"/> which was not able to process the object.</param> /// <param name="type">The type which was not handled.</param> public ValueProcessorCannotHandleTypeException([NotNull] IValueProcessor valueProcessor, [NotNull] Type type) : base(String.Format(ExceptionMessages.ValueProcessorCannotHandleTypeExceptionMessage, type.Name, valueProcessor.GetType().Name)) { this.ValueProcessor = valueProcessor; this.Type = type; }
/// <summary> /// Maps the <see cref="IValueProcessor"/> to the <see cref="Type"/>. /// </summary> /// <param name="registry">The <see cref="ITypeValueProcessorRegistry"/>.</param> /// <typeparam name="T">The <see cref="Type"/>.</typeparam> /// <param name="valueProcessor">The <see cref="IValueProcessor"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="registry"/>' and '<paramref name="valueProcessor"/>' cannot be null. </exception> public static void SetRegistration <T>([NotNull] this ITypeValueProcessorRegistry registry, [NotNull] IValueProcessor valueProcessor) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } if (valueProcessor == null) { throw new ArgumentNullException(nameof(valueProcessor)); } registry.SetRegistration(typeof(T), valueProcessor); }
/// <summary> /// Lookup the mapped <see cref="IValueProcessor"/> for the supplied <see cref="Type"/>. /// </summary> /// <param name="registry">The <see cref="ITypeValueProcessorRegistry"/>.</param> /// <typeparam name="T">The <see cref="Type"/> for which the mapped instance should be returned.</typeparam> /// <param name="result">The <see cref="IValueProcessor"/></param> /// <returns><c>true</c> if the mapping was found; otherwise, <c>false</c>.</returns> /// <exception cref="ArgumentNullException">The value of '<paramref name="registry"/>' cannot be null. </exception> public static Boolean TryLookup <T>([NotNull] this ITypeValueProcessorRegistry registry, [CanBeNull] out IValueProcessor result) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } return(registry.TryLookup(typeof(T), out result)); }
protected override ICollectionProcessor CreateCore(IValueProcessor elementProcessor) { Type processorType = _processorType.MakeGenericType(elementProcessor.DataType); return((ICollectionProcessor)Activator.CreateInstance(processorType, elementProcessor, Context)); }
public IReadOnlyCollectionProcessor(IValueProcessor elementProcessor, SpecFlowContext context) : base(elementProcessor, context, $"{nameof(IReadOnlyCollectionProcessor<T>)}<{elementProcessor?.FriendlyTypeName}>") { }
/// <summary> /// Initializes a new instance of the <see cref="QueryParameter"/> class. /// </summary> /// <param name="parameterName">The name of the parameter.</param> /// <param name="value">THe value of the parameter.</param> /// <param name="valueProcessor">An implementation of the <see cref="IValueProcessor"/> interface.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="parameterName"/>' cannot be null. </exception> public QueryParameter([NotNull] String parameterName, [CanBeNull] Object value, [CanBeNull] IValueProcessor valueProcessor) { if (String.IsNullOrEmpty(parameterName)) { throw new ArgumentNullException(nameof(parameterName)); } this.ParameterName = parameterName; this.Value = value; this.ValueProcessor = valueProcessor; this.TypeOfValue = value == null ? null : value.GetType(); }
public EnumerableProcessor(IValueProcessor elementProcessor, SpecFlowContext context) : base(elementProcessor, context, $"{nameof(EnumerableProcessor<T>)}<{elementProcessor?.FriendlyTypeName}>") { }
/// <summary> /// Adds a new mapping for the supplied <see cref="LambdaExpression"/>. /// </summary> /// <param name="source">The source object on which the <see cref="LambdaExpression"/> operates.</param> /// <param name="propertySelector">A <see cref="LambdaExpression"/> which selects the property which is used for the mapping.</param> /// <param name="parameterName">The parameter name which identifies the parameter in the query string.</param> /// <param name="valueProcessor">An instance of the <see cref="IValueProcessor"/> class.</param> /// <exception cref="MemberIsNotWritableException">The CanWrite property of the propertyInfo parameter returned <c>false</c>.</exception> /// <exception cref="PropertyNotFoundException">The propertyInfo parameter is not declared on the source.</exception> /// <exception cref="ArgumentNullException">The value of '<paramref name="source"/>', '<paramref name="propertySelector"/>', '<paramref name="parameterName"/>' and '<paramref name="valueProcessor"/>' cannot be null. </exception> public void AddPropertyMapping(Object source, LambdaExpression propertySelector, String parameterName, IValueProcessor valueProcessor) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (propertySelector == null) { throw new ArgumentNullException(nameof(propertySelector)); } if (String.IsNullOrEmpty(parameterName)) { throw new ArgumentNullException(nameof(parameterName)); } if (valueProcessor == null) { throw new ArgumentNullException(nameof(valueProcessor)); } PropertyInfo propertyInfo; var propertyInfoSource = this.lambdaExpressionInitializer.Initialize(source, propertySelector, out propertyInfo); this.AddPropertyMapping(new PropertyParserMap(propertyInfoSource, propertyInfo, new QueryParameter(parameterName, null, valueProcessor))); }