Skip to content

Add an API to allow registering TypeConverters for third-party types - #21476

Closed
simonrozsival wants to merge 3 commits into
dotnet:net9.0from
simonrozsival:add-new-type-conversion-app-builder-extensions-api
Closed

simonrozsival wants to merge 3 commits into
dotnet:net9.0from
simonrozsival:add-new-type-conversion-app-builder-extensions-api

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Description of Change

This is a follow-up to #21050 and #21459

This PR re-introduces an API that should serve as an escape hatch for developers migrating to NativeAOT who will run into problems with missing implicit operators. For their custom types, they can use the [TypeConverter] attribute, but for third-party types, there isn't a suitable mechanism.

This new API would allow registering type converters through the MauiAppBuilder.

Issues Fixed

Contributes to #19397

/cc @mattleibow

@simonrozsival
simonrozsival requested a review from a team as a code owner March 27, 2024 07:21
@rmarinho
rmarinho requested review from StephaneDelcroix and jonathanpeppers and removed request for jfversluis March 28, 2024 12:59

@jonathanpeppers jonathanpeppers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but probably someone on the MAUI team should decide if we want any changes to the new public APIs.

{
public static class TypeConversionAppBuilderExtensions
{
private static Dictionary<Type, TypeConverter>? s_typeConverters;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we can help it with various callers, but if this is static, the tests will have issues because multiple builder tests run in parallel - and each creates a new builder.

Is there a way to put this list into the service collection?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to figure this out but in the end I just gave up. The alternative I was considering was registering it as a service and then accessing it from the static TypeConversion class via Application.Current?.FindMauiContext() which we seem to often use for logging. I'm not sure if that solves the problem though.

@rmarinho
rmarinho requested a review from mattleibow April 9, 2024 11:08
@PureWeen PureWeen added the area-xaml XAML, CSS, Triggers, Behaviors label May 31, 2024
@simonrozsival

Copy link
Copy Markdown
Member Author

I'm closing this PR now. We can revisit it if this API becomes necessary later on.

@github-actions github-actions Bot locked and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-xaml XAML, CSS, Triggers, Behaviors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants