public override bool Matches(IEnumerable actual, IMatchDiagnostics diagnostics) { if (actual == null) { diagnostics.MisMatched(Description.With().Value("items are null").Value("expected", "not null")); return(false); } var items = AsEfficientList(actual); var matcher = new MatchContext(m_matchers); if (!matcher.CanStillMatch()) { //no matchers so all ok return(true); } matcher.NextMatcher(); Object lastMatchedItem = default(T); int lastMatchedItemIdx = -1; for (int i = 0; i < items.Count && matcher.CanStillMatch(); i++) { var item = items[i]; if (matcher.Matches(item, i, diagnostics)) { lastMatchedItem = item; lastMatchedItemIdx = i; matcher.NextMatcher(); } } //check all matchers matched if (matcher.CanStillMatch()) { matcher.AddMisMatchMessage(diagnostics, lastMatchedItem, lastMatchedItemIdx, items); return(false); } return(true); }