From e4b095a7663ef0c41d1d3198ef03192533fa1039 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Mon, 13 Jun 2022 16:27:16 -0600 Subject: Merge pull request #7894 from crobibero/search-hints (cherry picked from commit 0f75f177361906626e658da86d63583d5111f006) Signed-off-by: crobibero --- src/Jellyfin.Extensions/ReadOnlyListExtension.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/Jellyfin.Extensions/ReadOnlyListExtension.cs b/src/Jellyfin.Extensions/ReadOnlyListExtension.cs index 7785cfb49..ba99bb534 100644 --- a/src/Jellyfin.Extensions/ReadOnlyListExtension.cs +++ b/src/Jellyfin.Extensions/ReadOnlyListExtension.cs @@ -57,5 +57,21 @@ namespace Jellyfin.Extensions return -1; } + + /// + /// Get the first or default item from a list. + /// + /// The source list. + /// The type of item. + /// The first item or default if list is empty. + public static T? FirstOrDefault(this IReadOnlyList? source) + { + if (source is null || source.Count == 0) + { + return default; + } + + return source[0]; + } } } -- cgit v1.2.3