Skip to content

Conversation

@Erarndt
Copy link
Contributor

@Erarndt Erarndt commented Jul 14, 2025

Fixes #

Context

The BackingCollection property checks the backing collection for ICollection<T>.

image

This implementation creates a list copy if the underlying backing type doesn't implement ICollection<T>, and PropertyDictionary and ItemDictionary are two types that fall into this copying behavior.

image

This can be fixed by having them implement ICollection<T>. I don't see any allocations in this path after the change.

Changes Made

Testing

Notes

Copilot AI review requested due to automatic review settings July 14, 2025 18:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends PropertyDictionary<T> and ItemDictionary<T> to implement ICollection<T>, reducing unnecessary list allocations when interacting with backing collections.

  • PropertyDictionary now explicitly implements ICollection<T> methods.
  • ItemDictionary now implements ICollection<T>, adding IsReadOnly and CopyTo.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/Build/Collections/PropertyDictionary.cs Added ICollection<T> to class signature and provided explicit interface members
src/Build/Collections/ItemDictionary.cs Added ICollection<T> to class signature and implemented IsReadOnly and CopyTo methods

@SimaTian SimaTian merged commit 8c462c1 into dotnet:main Aug 25, 2025
9 checks passed
JanProvaznik pushed a commit that referenced this pull request Aug 26, 2025
…12170)

Fixes #

### Context

The `BackingCollection` property checks the backing collection for
`ICollection<T>`.

<img width="638" height="241" alt="image"
src="https://github.com/user-attachments/assets/9012ec98-7ddf-4ad4-8c5f-30c5e4520666"
/>

This implementation creates a list copy if the underlying backing type
doesn't implement `ICollection<T>`, and `PropertyDictionary` and
`ItemDictionary` are two types that fall into this copying behavior.

<img width="899" height="218" alt="image"
src="https://github.com/user-attachments/assets/049fd288-c1cb-4920-8e6d-a9bbd46a8a76"
/>

This can be fixed by having them implement `ICollection<T>`. I don't see
any allocations in this path after the change.

### Changes Made


### Testing


### Notes
@Erarndt Erarndt deleted the dev/erarndt/ICollectionPropertyDict branch September 22, 2025 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants