2019-01-13 20:01:16 +00:00
|
|
|
using System;
|
2013-11-22 15:33:14 +00:00
|
|
|
using System.Linq;
|
2019-01-13 19:24:58 +00:00
|
|
|
using MediaBrowser.Model.Querying;
|
2013-11-22 15:33:14 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Interface IHasItemFields
|
|
|
|
/// </summary>
|
|
|
|
public interface IHasItemFields
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the fields.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The fields.</value>
|
|
|
|
string Fields { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Class ItemFieldsExtensions.
|
|
|
|
/// </summary>
|
|
|
|
public static class ItemFieldsExtensions
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the item fields.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
/// <returns>IEnumerable{ItemFields}.</returns>
|
2017-08-19 19:43:35 +00:00
|
|
|
public static ItemFields[] GetItemFields(this IHasItemFields request)
|
2013-11-22 15:33:14 +00:00
|
|
|
{
|
|
|
|
var val = request.Fields;
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(val))
|
|
|
|
{
|
|
|
|
return new ItemFields[] { };
|
|
|
|
}
|
|
|
|
|
|
|
|
return val.Split(',').Select(v =>
|
|
|
|
{
|
2019-01-13 20:46:33 +00:00
|
|
|
if (Enum.TryParse(v, true, out ItemFields value))
|
2013-11-22 15:33:14 +00:00
|
|
|
{
|
|
|
|
return (ItemFields?)value;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
}).Where(i => i.HasValue).Select(i => i.Value).ToArray();
|
2013-11-22 15:33:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|