IHasItemFields.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using MediaBrowser.Model.Querying;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace MediaBrowser.Api
  6. {
  7. /// <summary>
  8. /// Interface IHasItemFields
  9. /// </summary>
  10. public interface IHasItemFields
  11. {
  12. /// <summary>
  13. /// Gets or sets the fields.
  14. /// </summary>
  15. /// <value>The fields.</value>
  16. string Fields { get; set; }
  17. }
  18. /// <summary>
  19. /// Class ItemFieldsExtensions.
  20. /// </summary>
  21. public static class ItemFieldsExtensions
  22. {
  23. /// <summary>
  24. /// Gets the item fields.
  25. /// </summary>
  26. /// <param name="request">The request.</param>
  27. /// <returns>IEnumerable{ItemFields}.</returns>
  28. public static ItemFields[] GetItemFields(this IHasItemFields request)
  29. {
  30. var val = request.Fields;
  31. if (string.IsNullOrEmpty(val))
  32. {
  33. return new ItemFields[] { };
  34. }
  35. return val.Split(',').Select(v =>
  36. {
  37. ItemFields value;
  38. if (Enum.TryParse(v, true, out value))
  39. {
  40. return (ItemFields?)value;
  41. }
  42. return null;
  43. }).Where(i => i.HasValue).Select(i => i.Value).ToArray();
  44. }
  45. }
  46. }