using System;
using System.Linq;
using MediaBrowser.Model.Querying;
namespace MediaBrowser.Api
{
///
/// Interface IHasItemFields.
///
public interface IHasItemFields
{
///
/// Gets or sets the fields.
///
/// The fields.
string Fields { get; set; }
}
///
/// Class ItemFieldsExtensions.
///
public static class ItemFieldsExtensions
{
///
/// Gets the item fields.
///
/// The request.
/// IEnumerable{ItemFields}.
public static ItemFields[] GetItemFields(this IHasItemFields request)
{
var val = request.Fields;
if (string.IsNullOrEmpty(val))
{
return Array.Empty();
}
return val.Split(',').Select(v =>
{
if (Enum.TryParse(v, true, out ItemFields value))
{
return (ItemFields?)value;
}
return null;
}).Where(i => i.HasValue).Select(i => i.Value).ToArray();
}
}
}