Fixing bug in CollectionExtensions RemoveAll method

This commit is contained in:
Chris Cameron
2017-10-13 16:50:37 -04:00
parent d6df8ca72b
commit 561f5da407
2 changed files with 19 additions and 19 deletions

View File

@@ -9,23 +9,6 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
public static class CollectionExtensions
{
/// <summary>
/// Removes items matching the predicate.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <param name="predicate"></param>
public static void RemoveAll<T>(this ICollection<T> extends, Func<T, bool> predicate)
{
if (extends == null)
throw new ArgumentNullException("extends");
if (predicate == null)
throw new ArgumentNullException("predicate");
extends.RemoveAll(extends.Where(predicate).ToArray());
}
/// <summary>
/// Removes all of the items from the other collection.
/// </summary>
@@ -40,7 +23,24 @@ namespace ICD.Common.Utils.Extensions
if (other == null)
throw new ArgumentNullException("other");
foreach (T item in other)
extends.RemoveAll(i => other.Contains(i));
}
/// <summary>
/// Removes items matching the predicate.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <param name="predicate"></param>
public static void RemoveAll<T>(this ICollection<T> extends, Func<T, bool> predicate)
{
if (extends == null)
throw new ArgumentNullException("extends");
if (predicate == null)
throw new ArgumentNullException("predicate");
foreach (T item in extends.Where(predicate).ToArray())
extends.Remove(item);
}
}

View File

@@ -42,7 +42,7 @@ namespace ICD.Common.Utils.Xml
throw new ArgumentNullException("extends");
if (!extends.HasAttributes)
return new IcdXmlAttribute[0];
return Enumerable.Empty<IcdXmlAttribute>();
List<IcdXmlAttribute> attributes = new List<IcdXmlAttribute>();
while (extends.MoveToNextAttribute())