Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Build/Collections/ItemDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Microsoft.Build.Collections
/// </remarks>
/// <typeparam name="T">Item class type to store</typeparam>
[DebuggerDisplay("#Item types={ItemTypes.Count} #Items={Count}")]
internal sealed class ItemDictionary<T> : IItemDictionary<T>
internal sealed class ItemDictionary<T> : ICollection<T>, IItemDictionary<T>
where T : class, IKeyed, IItem
{
/// <summary>
Expand Down Expand Up @@ -102,6 +102,8 @@ public ICollection<string> ItemTypes
}
}

public bool IsReadOnly => false;

/// <summary>
/// Returns the item list for a particular item type,
/// creating and adding a new item list if necessary.
Expand Down Expand Up @@ -403,6 +405,20 @@ private void AddProjectItem(T projectItem)
_nodes.Add(projectItem, node);
}

public void CopyTo(T[] array, int arrayIndex)
{
if (Count > array.Length - arrayIndex)
{
throw new ArgumentException(nameof(array));
}

foreach (T item in this)
{
array[arrayIndex] = item;
++arrayIndex;
}
}

/// <summary>
/// Custom enumerator that allows enumeration over all the items in the collection
/// as though they were in a single list.
Expand Down
27 changes: 26 additions & 1 deletion src/Build/Collections/PropertyDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Microsoft.Build.Collections
/// </remarks>
/// <typeparam name="T">Property or Metadata class type to store</typeparam>
[DebuggerDisplay("#Entries={Count}")]
internal sealed class PropertyDictionary<T> : IEnumerable<T>, IEquatable<PropertyDictionary<T>>, IPropertyProvider<T>, IDictionary<string, T>, IConstrainableDictionary<T>
internal sealed class PropertyDictionary<T> : IEnumerable<T>, ICollection<T>, IEquatable<PropertyDictionary<T>>, IPropertyProvider<T>, IDictionary<string, T>, IConstrainableDictionary<T>
where T : class, IKeyed, IValued, IEquatable<T>
{
/// <summary>
Expand Down Expand Up @@ -163,6 +163,8 @@ public int Count
}
}

bool ICollection<T>.IsReadOnly => false;

/// <summary>
/// Get the property with the specified name, or null if none exists.
/// Sets the property with the specified name, overwriting it if already exists.
Expand Down Expand Up @@ -451,6 +453,28 @@ bool ICollection<KeyValuePair<string, T>>.Remove(KeyValuePair<string, T> item)
return ((IDictionary<string, T>)this).Remove(item.Key);
}

/// <inheritdoc/>
void ICollection<T>.Add(T item) => Set(item);

/// <inheritdoc/>
bool ICollection<T>.Contains(T item)
{
return ((IDictionary<string, T>)this).TryGetValue(item.Key, out T existingItem) &&
EqualityComparer<T>.Default.Equals(existingItem, item);
}

/// <inheritdoc/>
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
using (_lock.EnterDisposableWriteLock())
{
_properties.CopyTo(array, arrayIndex);
}
}

/// <inheritdoc/>
bool ICollection<T>.Remove(T item) => Remove(item.Key);

#endregion

#region IEnumerable<KeyValuePair<string,T>> Members
Expand All @@ -471,6 +495,7 @@ IEnumerator<KeyValuePair<string, T>> IEnumerable<KeyValuePair<string, T>>.GetEnu

#endregion


/// <summary>
/// Removes any property with the specified name.
/// Returns true if the property was in the collection, otherwise false.
Expand Down