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 new ItemFields[] { };
}
return val.Split(',').Select(v =>
{
ItemFields value;
if (Enum.TryParse(v, true, out value))
{
return (ItemFields?)value;
}
return null;
}).Where(i => i.HasValue).Select(i => i.Value).ToArray();
}
}
}