You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The {OnIdiom ...} XAML markup extension is not trimmable because it needs to call Activator.CreateInstance(type) with a type that cannot be annotated with [DynamicallyAccessedMembers].
In the cases when XamlC can infer the type of the value the extension is holding (T), the non-generic {OnIdiom ...} extension can be transformed into a generic instance of OnIdiom<T> which is trimming friendly. We can also consider producing warnings for the cases when the compiler is not able to infer T and prompt the developer to transform the extension into OnIdiom<T> manually.
In this case, the compiler should be able to tell that all the values are strings and that the target property type is also a string. The transformed XAML should look like this:
In the following example (src/ProfiledAot/src/maui/App.xaml), there is a mismatch between the target property type and the type of the OnIdiom default value:
The compiler should be able to tell that the Margin property is of type Thickness which has a [TypeConverter(...)] attribute and so it can generate the IL to construct OnIdiom<Thickness> and use the TypeConverter to convert the string values into the target type.
This is a follow-up to #21927 (see #21927 (comment)).
The
{OnIdiom ...}
XAML markup extension is not trimmable because it needs to callActivator.CreateInstance(type)
with atype
that cannot be annotated with[DynamicallyAccessedMembers]
.In the cases when XamlC can infer the type of the value the extension is holding (
T
), the non-generic{OnIdiom ...}
extension can be transformed into a generic instance ofOnIdiom<T>
which is trimming friendly. We can also consider producing warnings for the cases when the compiler is not able to inferT
and prompt the developer to transform the extension intoOnIdiom<T>
manually.Example 1
Consider this example:
In this case, the compiler should be able to tell that all the values are strings and that the target property type is also a string. The transformed XAML should look like this:
Example 2
In the following example (
src/ProfiledAot/src/maui/App.xaml
), there is a mismatch between the target property type and the type of theOnIdiom
default value:The compiler should be able to tell that the
Margin
property is of typeThickness
which has a[TypeConverter(...)]
attribute and so it can generate the IL to constructOnIdiom<Thickness>
and use the TypeConverter to convert the string values into the target type./cc @StephaneDelcroix
The text was updated successfully, but these errors were encountered: