Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor WeakRefCollection to replace ArrayList with List<T> #10281

Closed
wants to merge 1 commit into from

Conversation

elachlan
Copy link
Contributor

@elachlan elachlan commented Nov 12, 2023

Related: #8140

Microsoft Reviewers: Open in CodeFlow

@elachlan elachlan requested a review from a team as a code owner November 12, 2023 23:26
@ghost ghost assigned elachlan Nov 12, 2023
@elachlan
Copy link
Contributor Author

@halgab could you please give this a quick review?

Copy link
Contributor

@halgab halgab left a comment

Choose a reason for hiding this comment

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

Happy to help!
I just see a minor potential improvement.

I don;t know if you've noticed, but this type is also defined here. I don't know if code consolidation between the winforms projects and System.Drawing.Common is something that should be considered, knowing that the latter targetting netfx makes it less profitable.

Other open questions I have about this type (but that are outside the scope of this PR):

  • should this be made generic?
  • if that's the case, should we be using WeakReference<T> under the hood? And more generally should we try and replace WeakReference with its generic counterpart across codebase?

return null;
}
set => InnerList[index] = CreateWeakRefObject(value);
get => InnerList[index] is WeakRefObject weakRef && weakRef.IsAlive ? weakRef.Target : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
get => InnerList[index] is WeakRefObject weakRef && weakRef.IsAlive ? weakRef.Target : null;
get => InnerList[index].Target;

According to the WeakReference docs, Target returns null if IsAlive is false

@JeremyKuhne JeremyKuhne self-requested a review November 13, 2023 20:44
@JeremyKuhne
Copy link
Member

@elachlan I don't think there is any real difference between the two WeakRefCollection classes. Presuming they are the same, it would be worth merging to Common and linking into both projects.

It would also be worth looking at whether these can be typed. Can this be WeakRefCollection<T>? And more correctly: WeakReferenceList<T> : IList<T>??

@elachlan
Copy link
Contributor Author

@JeremyKuhne what namespace do you want me to use if we merge them?

@JeremyKuhne
Copy link
Member

what namespace do you want me to use if we merge them?

@elachlan you can just put this in System.Collections or System.Collections.Generic if you make it of T. (As it is internal)

@elachlan
Copy link
Contributor Author

Closing in favor of #10291

@elachlan elachlan closed this Nov 14, 2023
@elachlan elachlan deleted the WeakRefCollection-Refactor branch November 14, 2023 00:03
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants