aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities/TagExtensions.cs
blob: 3e079a2a8e9cf4baf4c60fb6ecfd0195195411c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Linq;

namespace MediaBrowser.Controller.Entities
{
    public static class TagExtensions
    {
        public static void AddTag(this BaseItem item, string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            var current = item.Tags;

            if (!current.Contains(name, StringComparer.OrdinalIgnoreCase))
            {
                if (current.Length == 0)
                {
                    item.Tags = new[] { name };
                }
                else
                {
                    item.Tags = current.Concat(new [] { name }).ToArray();
                }
            }
        }
    }
}