Merge pull request #1336 from esdrubal/datatablereadxmlschema
[mono.git] / mcs / nunit24 / NUnitFramework / framework / SyntaxHelpers / ListMapper.cs
1 using System;\r
2 using System.Collections;\r
3 using System.Reflection;\r
4 \r
5 namespace NUnit.Framework.SyntaxHelpers\r
6 {\r
7         /// <summary>\r
8         /// ListMapper is used to transform a collection used as an actual argument\r
9         /// producing another collection to be used in the assertion.\r
10         /// </summary>\r
11         public class ListMapper\r
12         {\r
13                 ICollection original;\r
14 \r
15                 /// <summary>\r
16                 /// Construct a ListMapper based on a collection\r
17                 /// </summary>\r
18                 /// <param name="original">The collection to be transformed</param>\r
19                 public ListMapper( ICollection original )\r
20                 {\r
21                         this.original = original;\r
22                 }\r
23 \r
24                 /// <summary>\r
25                 /// Produces a collection containing all the values of a property\r
26                 /// </summary>\r
27                 /// <param name="name">The collection of property values</param>\r
28                 /// <returns></returns>\r
29                 public ICollection Property( string name )\r
30                 {\r
31                         ArrayList propList = new ArrayList();\r
32                         foreach( object item in original )\r
33                         {\r
34                                 PropertyInfo property = item.GetType().GetProperty( name, \r
35                                         BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );\r
36                                 if ( property == null )\r
37                                         throw new ArgumentException( string.Format(\r
38                                                 "{0} does not have a {1} property", item, name ) );\r
39 \r
40                                 propList.Add( property.GetValue( item, null ) );\r
41                         }\r
42 \r
43                         return propList;\r
44                 }\r
45         }\r
46 }\r