-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathContentEnumerableExtensions.cs
More file actions
24 lines (21 loc) · 1.08 KB
/
ContentEnumerableExtensions.cs
File metadata and controls
24 lines (21 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Collections.Generic;
namespace OrchardCore.ContentManagement;
public static class ContentEnumerableExtensions
{
/// <summary>
/// Retrieves an enumeration of a content part based on its type from an enumeration of content items.
/// </summary>
/// <returns>The content part enumeration or empty enumeration if it doesn't exist.</returns>
[Obsolete($"Use {nameof(GetOrCreate)} instead.")]
public static IEnumerable<TPart> As<TPart>(this IEnumerable<IContent>? contents)
where TPart : ContentPart =>
(contents?.SelectWhere(content => content.As<TPart>())).EmptyIfNull();
/// <summary>
/// Retrieves an enumeration of a content part based on its type from an enumeration of content items.
/// </summary>
/// <returns>The content part enumeration or empty enumeration if it doesn't exist.</returns>
public static IEnumerable<TPart> GetOrCreate<TPart>(this IEnumerable<IContent>? contents)
where TPart : ContentPart, new() =>
(contents?.SelectWhere(content => content.GetMaybe<TPart>())).EmptyIfNull();
}