Example #1
0
        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);
        }
Example #2
0
 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;
        }
Example #4
0
        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);
        }
Example #5
0
        /// <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;
        }
Example #6
0
        /// <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);
        }
Example #12
0
        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));
        }
Example #13
0
        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}>")
 {
 }
Example #15
0
 /// <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));
 }
Example #16
0
        /// <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);
Example #18
0
 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;
 }
Example #21
0
        /// <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);
        }
Example #22
0
        /// <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));
        }
Example #24
0
 public IReadOnlyCollectionProcessor(IValueProcessor elementProcessor, SpecFlowContext context)
     : base(elementProcessor, context, $"{nameof(IReadOnlyCollectionProcessor<T>)}<{elementProcessor?.FriendlyTypeName}>")
 {
 }
Example #25
0
        /// <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();
        }
Example #26
0
 public EnumerableProcessor(IValueProcessor elementProcessor, SpecFlowContext context)
     : base(elementProcessor, context, $"{nameof(EnumerableProcessor<T>)}<{elementProcessor?.FriendlyTypeName}>")
 {
 }
Example #27
0
        /// <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)));
        }