mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-19 08:36:37 +00:00
Switch to FirstOrDefault extension
This commit is contained in:
@@ -57,5 +57,21 @@ namespace Jellyfin.Extensions
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the first or default item from a list.
|
||||
/// </summary>
|
||||
/// <param name="source">The source list.</param>
|
||||
/// <typeparam name="T">The type of item.</typeparam>
|
||||
/// <returns>The first item or default if list is empty.</returns>
|
||||
public static T? FirstOrDefault<T>(this IReadOnlyList<T>? source)
|
||||
{
|
||||
if (source is null || source.Count == 0)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
return source[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user