Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robert Bullock 15 posts 75 karma points
    Jul 28, 2021 @ 12:43
    Robert Bullock
    0

    U8: Postion(), isFirst(), isLast(), etc.

    In Umbraco 7, I used the extensions for isFirst() and isLast() extensively. They're apparently gone in U8. Is there an easy way that doesn't require 10 lines of code to get these functions back?

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Aug 09, 2021 @ 20:12
    Alex Skrypnyk
    0

    Hi Robert,

    Just add these extensions to your project

    public static class IEnumerableExtensions
    {
        public static bool IsLast<T>(this IEnumerable<T> items, T item)
        {
            var last =  items.LastOrDefault();
            if (last == null)
                return false;
            return item.Equals(last); // OR Object.ReferenceEquals(last, item)
        }
    
        public static bool IsFirst<T>(this IEnumerable<T> items, T item)
        {
            var first =  items.FirstOrDefault();
            if (first == null)
                return false;
            return item.Equals(first);
        }
     }
    
  • Robert Bullock 15 posts 75 karma points
    Aug 09, 2021 @ 21:17
    Robert Bullock
    0

    That’s super helpful, thanks!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies