/// <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); }
public void GetValue_Returns_Expected_Value(string queryString, bool caseSensitiveKeys, string key, string join, string expected) { var dictionary = new QueryStringDictionary(queryString, caseSensitiveKeys); var actual = dictionary.GetValue(key, join); Assert.AreEqual(expected, actual); }
public void GetValue_Defaults_To_Comma() { var dictionary = new QueryStringDictionary("a=1&a=2"); Assert.AreEqual("1,2", dictionary.GetValue("a")); }
public void GetValue_Throws_If_Passed_Null_Join() { var dictionary = new QueryStringDictionary("a=1"); dictionary.GetValue("a", null); }