-
Notifications
You must be signed in to change notification settings - Fork 470
Create [AttachedBindableProperty]
#3024
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
base: main
Are you sure you want to change the base?
Conversation
pictos
left a comment
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.
Good work, I've a couple of comments about it
...aui.SourceGenerators.Internal/Generators/AttachedBindablePropertyAttributeSourceGenerator.cs
Outdated
Show resolved
Hide resolved
| static void ExecuteAllValues(SourceProductionContext context, ImmutableArray<AttachedBindablePropertySemanticValues> semanticValues) | ||
| { | ||
| // Pre-allocate dictionary with expected capacity | ||
| var groupedValues = new Dictionary<(string, string, string, string), List<AttachedBindablePropertySemanticValues>>(semanticValues.Length); |
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.
I would say to create a record type for the key
| var attachedBindablePropertiesCount = 0; | ||
| foreach (var value in values) | ||
| { | ||
| foreach (var abp in value.BindableProperties.AsImmutableArray()) |
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.
Why the usage of AsImmutableArray?
| { | ||
| var newBuffer = System.Buffers.ArrayPool<AttachedBindablePropertyModel>.Shared.Rent(attachedBindablePropertiesBuffer.Length * 2); | ||
| Array.Copy(attachedBindablePropertiesBuffer, newBuffer, attachedBindablePropertiesBuffer.Length); | ||
| System.Buffers.ArrayPool<AttachedBindablePropertyModel>.Shared.Return(attachedBindablePropertiesBuffer); |
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.
We aren't cleaning up the array when returning to the pool, this will make this array to hold values there, which can lead in bugs if we use the full Length of the array instead of the right number of BindableProperties
| } | ||
| } | ||
|
|
||
| var attachedBindableProperties = ImmutableArray.Create(attachedBindablePropertiesBuffer, 0, attachedBindablePropertiesCount); |
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.
Why not create the EquatableArray directly? Here we're allocating an ImmutableArray just to use it to allocate an EquatableArray. I see the EquatableArray ctor only allows ImmutableArray, maybe we could add an overload that accepts an Array. Since it holds the collection as an Array anyway
…/CommunityToolkit/Maui into Add-`-AttachedBindableProperty]`
…/CommunityToolkit/Maui into Add-`-AttachedBindableProperty]`
…/CommunityToolkit/Maui into Add-`-AttachedBindableProperty]`
Description of Change
This PR implements
[AttachedBindableProperty<T>("PropertyName")]:The attribute can be applied to a Class, like so:
Both usages will generate the following source code:
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
This PR is still in draft as some unit tests are still failing and need to be resolved.
This PR unblocks #3016 and #3000