/// /// <summary> * return a matching element from a collection of IMatches </summary> /// * @param <a> the data type /// * </param> /// * <param name="c"> the collection to search </param> /// * <param name="obj"> the search key for matches </param> /// * <returns> Vector of matching a </returns> /// public static List <IMatches> getMatches <a, T1>(ICollection <T1> c, a obj) where T1 : IMatches { if (c == null) { return(null); } IEnumerator <T1> it = c.GetEnumerator(); List <IMatches> v = new List <IMatches>(); while (it.MoveNext()) { IMatches m = it.Current; if (m.matches(obj)) { v.Add(m); } } return(v.Count == 0 ? null : v); }
/// /// <summary> * return a matching element from a collection of Imatches </summary> /// * @param <a> the data type /// * </param> /// * <param name="c"> the collection to search </param> /// * <param name="obj"> the search key for matches </param> /// * <param name="iSkip"> which one to grab, may be negative in which case we count -1=last, -2=second last... </param> /// * <returns> the matching <a> </returns> /// public static IMatches getMatch <a, T1>(ICollection <T1> c, a obj, int iSkip) where T1 : IMatches { int iSkipLocal = iSkip; if (c == null) { return(null); } if (iSkipLocal < 0) { List <IMatches> v = getMatches(c, obj); if (v == null) { return(null); } iSkipLocal = v.Count + iSkipLocal; if (iSkipLocal < 0) { return(null); } return(v[iSkipLocal]); } IEnumerator <T1> it = c.GetEnumerator(); while (it.MoveNext()) { IMatches m = it.Current; if (m.matches(obj) && iSkipLocal-- <= 0) { return(m); } } return(null); }