Add an API to allow registering TypeConverters for third-party types - #21476
simonrozsival wants to merge 3 commits into
Conversation
jonathanpeppers
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
I'm closing this PR now. We can revisit it if this API becomes necessary later on. |
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