public void op_Add_string_stringMultiple() { var obj = new DataCollection { { "name", "1,2,3" } }; Assert.Equal("name", obj[0].Key); Assert.Equal("name", obj[1].Key); Assert.Equal("name", obj[2].Key); Assert.Equal("1", obj[0].Value); Assert.Equal("2", obj[1].Value); Assert.Equal("3", obj[2].Value); obj.Add("name", "4,5,6"); Assert.Equal("name", obj[3].Key); Assert.Equal("name", obj[4].Key); Assert.Equal("name", obj[5].Key); Assert.Equal("4", obj[3].Value); Assert.Equal("5", obj[4].Value); Assert.Equal("6", obj[5].Value); }
public static DataCollection FromPostData(NameValueCollection form) { if (null == form) { throw new ArgumentNullException("form"); } var result = new DataCollection(); for (var i = 0; i < form.Count; i++) { var value = form[i]; if (null == value) { result.Add(form.Keys[i], form[i]); continue; } if (!value.Contains(",")) { result.Add(form.Keys[i], form[i]); continue; } #if NET20 foreach (var part in StringExtensionMethods.Split(value, ',', StringSplitOptions.RemoveEmptyEntries)) #else foreach (var part in value.Split(',', StringSplitOptions.RemoveEmptyEntries)) #endif { result.Add(form.Keys[i], part); } } return(result); }