TagExtensions.cs 817 B

123456789101112131415161718192021222324252627282930313233
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Linq;
  4. using Jellyfin.Extensions;
  5. namespace MediaBrowser.Controller.Entities
  6. {
  7. public static class TagExtensions
  8. {
  9. public static void AddTag(this BaseItem item, string name)
  10. {
  11. if (string.IsNullOrWhiteSpace(name))
  12. {
  13. throw new ArgumentNullException(nameof(name));
  14. }
  15. var current = item.Tags;
  16. if (!current.Contains(name, StringComparison.OrdinalIgnoreCase))
  17. {
  18. if (current.Length == 0)
  19. {
  20. item.Tags = new[] { name };
  21. }
  22. else
  23. {
  24. item.Tags = current.Concat(new[] { name }).ToArray();
  25. }
  26. }
  27. }
  28. }
  29. }