Convert a LinkItemCollection to a list of PageData in EPiServer 7

I found a nice little snippet from Joel Abrahamsson on how to convert a LinkItemCollection to a list of PageDatas instead. So I used his code as a base to update it to EPiServer 7.

using System.Collections.Generic;
using EPiServer;
using EPiServer.Core;
using EPiServer.ServiceLocation;
using EPiServer.SpecializedProperties;
using EPiServer.Web;

namespace Classes.Extensions
{
	public static class LinkItemCollectionExtensions
	{
		public static List<PageData> ToPages(this LinkItemCollection linkItemCollection)
		{
			var pages = new List<PageData>();

			if (linkItemCollection == null || linkItemCollection.Count.Equals(0))
				return pages;
	
			var ctx = ServiceLocator.Current.GetInstance<IContentLoader>();

			foreach (var linkItem in linkItemCollection)
			{
				string linkUrl;

				if(!PermanentLinkMapStore.TryToMapped(linkItem.Href, out linkUrl))
					continue;

				if(string.IsNullOrWhiteSpace(linkUrl))
					continue;

				var pageReference = PageReference.ParseUrl(linkUrl);

				if(PageReference.IsNullOrEmpty(pageReference))
					continue;

				pages.Add(ctx.Get<PageData>(pageReference));
			}

			return pages;
		}
	}
}