Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IList<Breadcrumb> crumbs = new List<Breadcrumb>();
- bool foundCurrent = false;
- for (int a = 0; a < cachedCrumbs.Count; a++)
- {
- crumbs.Add(crumbs[a]);
- if (foundCurrent)
- {
- break;
- }
- foundCurrent = (crumbs[a + 1] != null && ((Breadcrumb)crumbs[a + 1]).IsCurrent);
- }
- bool foundCurrent = false;
- var crumbs = cachedCrumbs.TakeWhile(crumb => !foundCurrent)
- .Select(crumb => {
- foundCurrent = crumb == null || !crumb.IsCurrent;
- return crumb; });
- var crumbs = cachedCrumbs.NewMethod(crumb => crumb == null || !crumb.IsCurrent);
- IList<Breadcrumb> crumbs = new List<Breadcrumb>();
- for (int a = 0; a < cachedCrumbs.Count; a++)
- {
- crumbs.Add(cachedCrumbs[a]);
- if (cachedCrumbs[a] != null && cachedCrumbs[a].IsCurrent)
- {
- break;
- }
- }
- IList<Breadcrumb> crumbs = new List<BreadCrumb>();
- foreach (Breadcrumb crumb in cachedCrumbs)
- {
- crumbs.Add(crumb);
- if (crumb != null && crumb.IsCurrent)
- {
- break;
- }
- }
- // find the current item
- var currentItem = cachedCrumbs.First(c => c.IsCurrent);
- var currentIdx = cachedCrumbs.IndexOf(currentItem);
- // get all items upto current item
- var crumbs = cachedCrumbs.Take(currentIdx + 2);
- public static IEnumerable<T> TakeUpto<T>(this IList<T> theList, Func<T, bool> predicate)
- {
- var targetItem = theList.First(predicate);
- var targetIdx = theList.IndexOf(targetItem);
- return theList.Take(targetIdx + 2);
- }
- var crumbs = cachedCrumbs.TakeUpto(c => c.IsCurrent);
- public static IEnumerable<T> TakeUpto<T>(this IEnumerable<T> theList, Func<T, bool> predicate)
- {
- foreach (T element in theList)
- {
- yield return element;
- if (predicate(element))
- {
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment