-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add new constructor to AvaloniaDictionary and include unit tests #17311 #17312
Conversation
You can test this PR using the following package version. |
|
@cla-avalonia agree |
Should the new constructor be an IDictionary interface rather than concrete class? |
API diff for review: namespace Avalonia.Collections
{
public partial class AvaloniaDictionary {
{
+ public AvaloniaDictionary(System.Collections.Generic.Dictionary<TKey, TValue> initialDictionary) { }
}
} |
You can test this PR using the following package version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notes from the API meeting:
As suggested in #17312 (comment), use the most complete constructor.
Expected API:
AvaloniaDictionary(IEnumerable<KeyValuePair<TKey,TValue>> collection, IEqualityComparer<TKey>? comparer);
You can test this PR using the following package version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
/// </summary> | ||
public AvaloniaDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey>? comparer = null) | ||
{ | ||
if (dictionary != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you can remove this check and the throw
below. Let the Dictionary
's constructor throw on its own, as its documented to do so. There's no real point in checking the same thing several times.
#17311
What does the pull request do?
This pull request adds a new constructor to
AvaloniaDictionary<TKey, TValue>
that accepts an existingDictionary<TKey, TValue>
. The goal is to provide an easier and more efficient way to initializeAvaloniaDictionary
with pre-existing dictionary data.What is the current behavior?
Currently,
AvaloniaDictionary
lacks a constructor that directly accepts aDictionary<TKey, TValue>
. Developers have to manually copy elements into AvaloniaDictionary, which increases boilerplate code and is less efficient.What is the updated/expected behavior with this PR?
With this PR, developers can initialize AvaloniaDictionary with an existing dictionary directly, simplifying the code and reducing manual effort.
To test:
Checklist
Breaking changes
No breaking changes are introduced, as this PR simply adds an overload to the existing constructors.
Obsoletions / Deprecations
Fixed issues