IHasDtoOptions.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using MediaBrowser.Controller.Dto;
  2. using MediaBrowser.Model.Entities;
  3. using System;
  4. using System.Linq;
  5. namespace MediaBrowser.Api
  6. {
  7. public interface IHasDtoOptions : IHasItemFields
  8. {
  9. bool? EnableImages { get; set; }
  10. int? ImageTypeLimit { get; set; }
  11. string EnableImageTypes { get; set; }
  12. }
  13. public static class HasDtoOptionsExtensions
  14. {
  15. public static DtoOptions GetDtoOptions(this IHasDtoOptions request)
  16. {
  17. var options = new DtoOptions();
  18. options.Fields = request.GetItemFields().ToList();
  19. options.EnableImages = request.EnableImages ?? true;
  20. if (request.ImageTypeLimit.HasValue)
  21. {
  22. options.ImageTypeLimit = request.ImageTypeLimit.Value;
  23. }
  24. if (!string.IsNullOrWhiteSpace(request.EnableImageTypes))
  25. {
  26. options.ImageTypes = (request.EnableImageTypes ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)).ToList();
  27. }
  28. return options;
  29. }
  30. }
  31. }