|
From: <joe...@us...> - 2003-01-21 18:16:15
|
Update of /cvsroot/nmock/nmock/src/NMock/Constraints
In directory sc8-pr-cvs1:/tmp/cvs-serv16434/src/NMock/Constraints
Modified Files:
Constraints.cs
Log Message:
PropertyIs can now support properties of properties.... eg "Name.FirstName.Length"
Index: Constraints.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/Constraints/Constraints.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Constraints.cs 21 Jan 2003 17:36:00 -0000 1.4
--- Constraints.cs 21 Jan 2003 18:16:13 -0000 1.5
***************
*** 364,367 ****
--- 364,370 ----
/// This constraint decorates another constraint, allowing it to test
/// a property of the object, rather than the property itself.
+ ///
+ /// Properties of properties can be specified by using the
+ /// "Property.SubProperty" notation.
/// </summary>
public class PropertyIs : IConstraint
***************
*** 386,393 ****
return false;
}
Type type = val.GetType();
PropertyInfo propertyInfo = type.GetProperty(property);
! object propertyValue = propertyInfo.GetValue(val, null);
! return constraint.Eval(propertyValue);
}
--- 389,406 ----
return false;
}
+ // split "a.b.c" into "a", "b", "c"
+ object propertyValue = val;
+ foreach(string propertyBit in property.Split(new char[] {'.'}))
+ {
+ propertyValue = getProperty(propertyValue, propertyBit);
+ }
+ return constraint.Eval(propertyValue);
+ }
+
+ private object getProperty(object val, string property)
+ {
Type type = val.GetType();
PropertyInfo propertyInfo = type.GetProperty(property);
! return propertyInfo.GetValue(val, null);
}
|