Пример #1
0
        public void Test()
        {
            var user = new User();

            ParameterCollection col = new ParameterCollection {{"Name", "Jonas"}, {"Age", "17"}};
            PropertyAssigner.Assign(user, col);
            Assert.Equal("Jonas", user.Name);
            Assert.Equal(17, user.Age);
        }
		public void Test()
		{
			ParameterCollection temp = new ParameterCollection();
			temp.Add("schedule[day][1][open]", "08:00");
			temp.Add("schedule[day][1][close]", "16:00");
			temp.Add("schedule[day][2][open]", "07:00");
			temp.Add("schedule[day][2][close]", "16:00");

			ArrayParameterCollection col = new ArrayParameterCollection(temp);
			Assert.Equal("07:00", col["schedule"]["day"]["2"]["open"].Value);
		}
        /// <summary>
        /// Get parameters 
        /// </summary>
        /// <param name="arrayName">Sub array (text array)</param>
        /// <returns></returns>
        public IParameterCollection GetParameters(string arrayName)
        {
            var collection = new ParameterCollection();
            arrayName = arrayName + "[";
            foreach (var item in _items)
            {
                if (!item.Key.StartsWith(arrayName)) continue;
                int pos = arrayName.IndexOf("]");
                if (pos == -1) continue;

                string name = arrayName.Substring(arrayName.Length, pos - arrayName.Length);
                foreach (string value in item.Value)
                    collection.Add(name, value);
            }

            return collection;
        }