Пример #1
0
 public static void AddData(this ITag tag, string key, string value)
 {
     if (string.IsNullOrWhiteSpace(key))
     {
         throw new ArgumentException();
     }
     tag.AddAttribute($"data-{key}", value);
 }
Пример #2
0
 public static void AddTitle(this ITag tag, string title)
 {
     if (string.IsNullOrWhiteSpace(title))
     {
         throw new ArgumentException();
     }
     tag.AddAttribute("title", title);
 }
Пример #3
0
        public static void AddClasses(this ITag tag, params string[] classes)
        {
            var distinctClasses = classes.GroupBy(c => c)
                                  .Select(c => c.First())
                                  .Where(c => !string.IsNullOrWhiteSpace(c));

            tag.AddAttribute("class", string.Join(" ", distinctClasses));
        }
Пример #4
0
        public static void AddId(this ITag tag, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("id can't be empty");
            }

            if (!id[0].IsLetter())
            {
                throw new ArgumentException("first id character must be a letter");
            }

            for (int i = 1; i < id.Length; i++)
            {
                if (!id[i].IsValidIdCharacter())
                {
                    throw new ArgumentException($"id cannot contain character {id[i]}");
                }
            }

            tag.AddAttribute("id", id);
        }