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

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

Open
wants to merge 2 commits into
base: net9.0
Choose a base branch
from

Conversation

simonrozsival
Copy link
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
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

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
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
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.

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

Successfully merging this pull request may close these issues.

None yet

4 participants