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

Improve AvaloniaList/List compiler support #10109

Closed
maxkatz6 opened this issue Jan 28, 2023 · 1 comment · Fixed by #11073
Closed

Improve AvaloniaList/List compiler support #10109

maxkatz6 opened this issue Jan 28, 2023 · 1 comment · Fixed by #11073

Comments

@maxkatz6
Copy link
Member

maxkatz6 commented Jan 28, 2023

Is your feature request related to a problem? Please describe.

Right now, when developer sets a string value to the AvaloniaList property, compiler will emit "AvaloniaListConverter".
Which in runtime will use TypeUtilities.TryConvert marked as unsafe for reflection, as it can fallback to it in some code paths.

Instead, compiler should attempt to parse the list in compile time, and if it was successful, emit pre-constructed collection.

Describe the solution you'd like

To have a flexible support, we should add an attribute, which will work as a hint for the compiler, how to separate items in the collection.
I.e., Control.Classes is separated by spaces, while AvaloniaListConverter expects comma separated items.
We can expect something like:

[AvaloniaListAttribute(Separators = new [] { " " })]
public Classes Classes { get { } set { } }

[AvaloniaListAttribute(Separators = new [] { "," })]
public Avalonia.Collections.AvaloniaList<double>? Dashes { get { } set { } }

Additional context

It improves following APIs:

// Shape
        public Avalonia.Collections.AvaloniaList<double>? StrokeDashArray { get { throw null; } set { } }
// TickBar/Slider
        public Avalonia.Collections.AvaloniaList<double> Ticks { get { throw null; } set { } }
// Border
        public Avalonia.Collections.AvaloniaList<double>? BorderDashArray { get { throw null; } set { } }
// DashStyle
        public Avalonia.Collections.AvaloniaList<double>? Dashes { get { throw null; } set { } }
// PolylineGeometry
        public Avalonia.Points Points { get { throw null; } set { } }

Right now, we already do the same for Control.Classes property and Grid row/column definitions as a special case. It can be generalized.

Currently Avalonia.Themes.Fluent has exactly one usage of AvaloniaListConverter which can be avoided completely.

@maxkatz6
Copy link
Member Author

maxkatz6 commented Jan 28, 2023

Additional context # 2

WinUI/UWP has implemented a very similar idea but hardcoded it to only commas (and semicolors?). There is quite a lot of discussions about this, while I believe we should use an attribute as a hint, while keeping default behavior just like AvaloniaListConverter, i.e. - commas.
microsoft/microsoft-ui-xaml#673
https://github.com/microsoft/microsoft-ui-xaml-specs/blob/master/active/gridsyntax/GridSyntaxSpec2.md#other-use-cases

Also, there was an interesting idea to introduce markup extension - kekekeks/XamlX#28. Which, in my opinion, should be a separated feature, because we already have support for string-to-array parsing in runtime using converter.

@maxkatz6 maxkatz6 changed the title AvaloniaList/List compiler support Improve AvaloniaList/List compiler support Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant