예제 #1
0
 /// <summary>
 /// Adds a new property mapping.
 /// </summary>
 /// <param name="propertyParserMap">The <see cref="PropertyParserMap"/> to add.</param>
 /// <exception cref="ArgumentException">"A parameter with the specified name already exists."</exception>
 /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyParserMap"/>' cannot be null. </exception>
 private void AddPropertyMapping(PropertyParserMap propertyParserMap)
 {
     if (!this.TryAddPropertyMapping(propertyParserMap))
     {
         throw new InvalidOperationException(String.Format("The QueryString does not contain the key '{0}'.", propertyParserMap.Parameter.ParameterName));
     }
 }
예제 #2
0
        /// <summary>
        /// Search for the mappable query parameter with the supplied name and checks if no mapping already exist. If these conditions are met the <see cref="PropertyParserMap"/> is added.
        /// </summary>
        /// <param name="propertyParserMap">The <see cref="PropertyParserMap"/>.</param>
        /// <returns><c>true</c> if the mapping was added; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyParserMap"/>' cannot be null. </exception>
        public Boolean TryAddPropertyMapping(PropertyParserMap propertyParserMap)
        {
            if (propertyParserMap == null)
            {
                throw new ArgumentNullException(nameof(propertyParserMap));
            }

            if (propertyParserMap.Parameter.TypeOfValue != null && propertyParserMap.Parameter.ValueProcessor == null)
            {
                propertyParserMap.Parameter.ValueProcessor = this.ValueProcessorFactory.GetUrlValueProcessorForType(propertyParserMap.Parameter.TypeOfValue);
            }

            if (this.queryficationDictionary.ContainsKey(propertyParserMap.Parameter.ParameterName) && !this.Exists(propertyParserMap.Parameter.ParameterName))
            {
                this.propertyParserMaps.Add(propertyParserMap);
                return(true);
            }

            return(false);
        }