TagExtensions.cs 907 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MediaBrowser.Model.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("name");
  14. }
  15. var current = item.Tags;
  16. if (!current.Contains(name, StringComparer.OrdinalIgnoreCase))
  17. {
  18. if (current.Length == 0)
  19. {
  20. item.Tags = new[] { name };
  21. }
  22. else
  23. {
  24. var list = current.ToArray(current.Length + 1);
  25. list[list.Length - 1] = name;
  26. item.Tags = list;
  27. }
  28. }
  29. }
  30. }
  31. }