1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Components
.Binder
.Tests
18 using System
.Collections
.Specialized
;
20 public class TestUtils
23 /// Parse a string in this format:
26 /// Person[0].Name = Gi Joe
27 /// Person[0].Age = 32
28 /// Person[1].Name = Mary
29 /// Person[1].Age = 16
31 /// and return a NameValueCollection with these elements
33 /// "Person@count" => "2"
34 /// "Person[0].Name" => "Gi Joe"
35 /// "Person[0].Age" => "32"
36 /// "Person[1].Name" => "Mary"
37 /// "Person[1].Age" => "16"
39 /// <param name="data"></param>
40 /// <returns></returns>
42 /// Notice that any that leading and trailing spaces are discarded
44 public static NameValueCollection
ParseNameValueString(String data
)
46 NameValueCollection args
= new NameValueCollection();
50 foreach(string nameValue
in data
.Split('\n'))
52 if (nameValue
.Trim() == "") continue;
54 string[] pair
= nameValue
.Split('=');
55 args
.Add(pair
[0].Trim(), pair
[1].Trim());