TagExtensions.cs 756 B

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