Files
Umbraco-CMS/src/Umbraco.Abstractions/PublishedElementExtensions.cs
Andy Butland 9e89e18492 Migrated various IPublishedContent extension methods from web to core, removin use of service location.
Kept the original methods passing through to the core ones, providing the service located dependencies.
Used one of these migrated methods in the Umbraco.Infrastructure.PublishedCache project.
2020-01-31 15:33:31 +01:00

28 lines
818 B
C#

using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
namespace Umbraco.Core
{
/// <summary>
/// Provides extension methods for <c>IPublishedElement</c>.
/// </summary>
public static class PublishedElementExtensions
{
#region OfTypes
// the .OfType<T>() filter is nice when there's only one type
// this is to support filtering with multiple types
public static IEnumerable<T> OfTypes<T>(this IEnumerable<T> contents, params string[] types)
where T : IPublishedElement
{
if (types == null || types.Length == 0) return Enumerable.Empty<T>();
return contents.Where(x => types.InvariantContains(x.ContentType.Alias));
}
#endregion
}
}