Пример #1
0
 private void RemoveAttribute(List <Animal> list, AnimalAttribute attrToRemove)
 {
     foreach (var i in list)
     {
         var item = i.Attributes.FirstOrDefault(v => v.Type == attrToRemove.Type && v.Text == attrToRemove.Text);
         if (item != null)
         {
             i.Attributes.Remove(item);
         }
     }
 }
Пример #2
0
        public void AddAttribute(AnimalAttribute attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            if (string.IsNullOrWhiteSpace(attribute.Text))
            {
                throw new ArgumentException("AnimalAttribute cannot be null or empty");
            }

            if (!Attributes.Exists(a =>
                                   a.Type == attribute.Type &&
                                   a.Text.Equals(attribute.Text, StringComparison.OrdinalIgnoreCase)))
            {
                Attributes.Add(attribute);
            }
        }