using System;
using System.Collections;
using System.Reflection;
namespace NUnit.Framework.SyntaxHelpers
{
///
/// ListMapper is used to transform a collection used as an actual argument
/// producing another collection to be used in the assertion.
///
public class ListMapper
{
ICollection original;
///
/// Construct a ListMapper based on a collection
///
/// The collection to be transformed
public ListMapper( ICollection original )
{
this.original = original;
}
///
/// Produces a collection containing all the values of a property
///
/// The collection of property values
///
public ICollection Property( string name )
{
ArrayList propList = new ArrayList();
foreach( object item in original )
{
PropertyInfo property = item.GetType().GetProperty( name,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
if ( property == null )
throw new ArgumentException( string.Format(
"{0} does not have a {1} property", item, name ) );
propList.Add( property.GetValue( item, null ) );
}
return propList;
}
}
}