2013-12-05 09:50:21 -07:00
|
|
|
|
using System;
|
2017-08-09 12:56:38 -07:00
|
|
|
|
using System.Collections.Generic;
|
2013-12-05 09:50:21 -07:00
|
|
|
|
using System.Linq;
|
2017-08-09 12:56:38 -07:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2013-12-05 09:50:21 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
|
{
|
|
|
|
|
public static class TagExtensions
|
|
|
|
|
{
|
2016-06-02 10:43:29 -07:00
|
|
|
|
public static void AddTag(this BaseItem item, string name)
|
2013-12-05 09:50:21 -07:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("name");
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 12:56:38 -07:00
|
|
|
|
var current = item.Tags;
|
|
|
|
|
|
|
|
|
|
if (!current.Contains(name, StringComparer.OrdinalIgnoreCase))
|
2013-12-05 09:50:21 -07:00
|
|
|
|
{
|
2017-08-09 12:56:38 -07: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 09:50:21 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|