예제 #1
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="modelType"></param>
        /// <param name="typeParserResolver"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public object BuildModel(Type modelType, TypeParserResolver typeParserResolver, QueryStringDictionary values)
        {
            if (modelType == null)
            {
                throw new ArgumentNullException(nameof(modelType));
            }
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            var result = Activator.CreateInstance(modelType);

            foreach (var propertyInfo in modelType.GetProperties())
            {
                if (values.ContainsKey(propertyInfo.Name))
                {
                    var valueText   = values.GetValue(propertyInfo.Name);
                    var parsedValue = Parser.ParseType(
                        propertyInfo.PropertyType,
                        valueText,
                        typeParserResolver
                        );
                    propertyInfo.SetValue(result, parsedValue);
                }
            }

            return(result);
        }
예제 #2
0
        public void ContainsKey_Returns_Expected_Value(string queryString, bool caseSensitiveKeys, string searchKey, bool expected)
        {
            var dictionary = new QueryStringDictionary(queryString, caseSensitiveKeys);

            Assert.AreEqual(expected, dictionary.ContainsKey(searchKey));
        }