Skip to content

Conversation

@steveharter
Copy link
Contributor

Removed the separate cached dictionary to contain the converters that support number handling and replaced with a virtual method SupportsQuotedNumbers that returns true for the appropriate built-in converters.

This improves maintainbility especially for non-trivial converters like Enum and for other work that I'm prototyping. In the future, this would also be useful if we want to enable custom converters to add their own number handling.

@ghost
Copy link

ghost commented Feb 12, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details

Removed the separate cached dictionary to contain the converters that support number handling and replaced with a virtual method SupportsQuotedNumbers that returns true for the appropriate built-in converters.

This improves maintainbility especially for non-trivial converters like Enum and for other work that I'm prototyping. In the future, this would also be useful if we want to enable custom converters to add their own number handling.

Author: steveharter
Assignees: steveharter
Labels:

area-System.Text.Json

Milestone: 6.0.0

@steveharter
Copy link
Contributor Author

steveharter commented Feb 15, 2021

@jozkee after thinking about this more, this could break some edge cases where a custom primitive (Int32 etc) converter registered with the options won't work with quoted numbers since that support is based on internal converter methods. Was this a reason for the current implementation? In either case, this edge case would likely cause issues anyway since their custom logic wouldn't be applied to quoted numbers.

One factor I didn't mention earlier is that we need a fast way to convert a primitive to a string for the writable DOM work. It is not performant to new up a writer, get a pooled buffer, possibly transcode UTF8 to string, etc. just to convert a primitive to a string. So if we decide not to take this PR I can close this PR and address the refactoring with the writable DOM work instead including making the internal methods public.

@jozkee
Copy link
Member

jozkee commented Feb 16, 2021

a custom primitive (Int32 etc) converter registered with the options won't work with quoted numbers since that support is based on internal converter methods.

@steveharter if this PR is changing how we get the converter for the dictionary key by not only looking at the built-in converters but also at custom ones, then yes, that would be breaking since Read/WriteWithQuotes methods are not yet exposed.

I think your approach could be possible if #46520 was addressed.

Base automatically changed from master to main March 1, 2021 09:07
@steveharter
Copy link
Contributor Author

@steveharter if this PR is changing how we get the converter for the dictionary key by not only looking at the built-in converters but also at custom ones, then yes, that would be breaking since Read/WriteWithQuotes methods are not yet exposed.

OK closing this.

We should add a test that uses a custom converter for a number type + use the quoted number feature.

I may create a new PR that addresses other items here including the usage of ConcurrentDictionary here (standard Dictionary is fine since there are no threading issues) and also remove the double instances of the built-in converters in the two dictionaries.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 11, 2021
@steveharter steveharter deleted the KeyConverter branch September 30, 2024 19:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants