2 using System.Collections;
\r
3 using System.Reflection;
\r
5 namespace NUnit.Framework.SyntaxHelpers
\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
11 public class ListMapper
\r
13 ICollection original;
\r
16 /// Construct a ListMapper based on a collection
\r
18 /// <param name="original">The collection to be transformed</param>
\r
19 public ListMapper( ICollection original )
\r
21 this.original = original;
\r
25 /// Produces a collection containing all the values of a property
\r
27 /// <param name="name">The collection of property values</param>
\r
28 /// <returns></returns>
\r
29 public ICollection Property( string name )
\r
31 ArrayList propList = new ArrayList();
\r
32 foreach( object item in original )
\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
40 propList.Add( property.GetValue( item, null ) );
\r