2013-12-05 16:50:21 +00:00
|
|
|
|
using System;
|
2017-08-09 19:56:38 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-12-05 16:50:21 +00:00
|
|
|
|
using System.Linq;
|
2017-08-09 19:56:38 +00:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2013-12-05 16:50:21 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
|
{
|
|
|
|
|
public static class TagExtensions
|
|
|
|
|
{
|
2016-06-02 17:43:29 +00:00
|
|
|
|
public static void AddTag(this BaseItem item, string name)
|
2013-12-05 16:50:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("name");
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 19:56:38 +00:00
|
|
|
|
var current = item.Tags;
|
|
|
|
|
|
|
|
|
|
if (!current.Contains(name, StringComparer.OrdinalIgnoreCase))
|
2013-12-05 16:50:21 +00:00
|
|
|
|
{
|
2017-08-09 19:56:38 +00:00
|
|
|
|
if (current.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
item.Tags = new[] { name };
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var list = current.ToArray(current.Length + 1);
|
|
|
|
|
list[list.Length - 1] = name;
|
|
|
|
|
|
|
|
|
|
item.Tags = list;
|
|
|
|
|
}
|
2013-12-05 16:50:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|