Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Extension method to match by expression on object #99

wants to merge 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 15, 2012
  1. @TomasEkeli
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 0 deletions.
  1. +8 −0 Source/Machine.Specifications/ExtensionMethods.cs
8 Source/Machine.Specifications/ExtensionMethods.cs
@@ -159,6 +159,14 @@ public static void ShouldNotBeOfType(this object actual, Type expected)
+ public static void ShouldMatch<T>(this T actual, Expression<Func<T, bool>> condition)
+ {
+ var matches = condition.Compile().Invoke(actual);
+ if (matches) return;
+ throw new SpecificationException(string.Format("Should match expression [{0}], but does not.", condition));
+ }
public static void ShouldEachConformTo<T>(this IEnumerable<T> list, Expression<Func<T, bool>> condition)
var source = new List<T>(list);
Something went wrong with that request. Please try again.