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

Array element type ignored by Xaml compiler #11946

Closed
TomEdwardsEnscape opened this issue Jun 28, 2023 · 6 comments · Fixed by kekekeks/XamlX#98, #13328 or #13331
Closed

Array element type ignored by Xaml compiler #11946

TomEdwardsEnscape opened this issue Jun 28, 2023 · 6 comments · Fixed by kekekeks/XamlX#98, #13328 or #13331

Comments

@TomEdwardsEnscape
Copy link
Contributor

The method AvaloniaXamlIlLanguageParseIntrinsics.GetElementType only works for IEnumerable<T> types. To support arrays too, these lines should be added:

if (type.IsArray)
{
    return type.ArrayElementType;
}

Unfortunately this change won't have an immediate effect due to kekekeks/XamlX/issues/89, which causes ArrayElementType to return the wrong value.

However, once both of these bugs are fixed then Avalonia starts to support defining arrays with comma-delimited strings! e.g. MyIntArray="1,2,3" or MyDockArray="Top,Bottom,Top". This syntax is something that I wanted to write earlier today, but was unable to.

To Reproduce
Add an array property to a control, then try to assign a value to it in XAML. You will receive a compiler error that looks like this:

Avalonia error AVLN: 0004: XamlX.XamlLoadException: Unable to find suitable setter or adder for property [...] of type [...] for argument netstandard:System.String, available setter parameter lists are:

Expected behavior
Arrays can be defined in XAML with comma-delimited strings, using the same parsing rules as single values of the same type.

@maxkatz6
Copy link
Member

However, once both of these bugs are fixed then Avalonia starts to support defining arrays with comma-delimited strings!

Side note, this syntax is already working at least with other kinds of collections, like IList or AvaloniaList.

@TomEdwardsEnscape
Copy link
Contributor Author

TomEdwardsEnscape commented Jun 29, 2023

Thanks for the tip. I can confirm that those two types work, but as far as I can tell only it's them and IReadOnlyList<T> which are supported. If the property is List<T> (the class), ICollection<T>, or even IEnumerable<T> then a compiler error is emitted instead.

@TomEdwardsEnscape
Copy link
Contributor Author

To fix this bug, a change also has to be made to Avalonia. Or does it work already?

@timunie
Copy link
Contributor

timunie commented Oct 20, 2023

Would be great if anyone could try using nightly build.

/cc @TomEdwardsEnscape

@workgroupengineering
Copy link
Contributor

#13328

@TomEdwardsEnscape
Copy link
Contributor Author

It's not fixed yet, see the PR above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants