-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
Two issues here:
CanConvertFrom returns true when the input parameter is a string.
This is not correct:
- The string should contain exactly two elements separated by the "culture" list separator
- It should be possible than both elements are converted into int numbers
ConvertFrom is trying to convert the values even the list of values provided has not 2 elements
This does not look "friendly".
If the result of the split is not returning exactly two elements, what is the sense of trying to convert them?. Even if you are able to convert, the result will be a exception raised because the number of elements
In case there are problems with the list separator (different culture when the value was created than when it is consumed), it will be much more useful raise the exception before trying to convert the elements with a message describing the problem:
"Unable to get the expected elements (2) when splitting the string ("my string") using the list separator ("sep") from the regional settings (culture)"
Reproduction Steps
Try to convert "1024,768" when regional settings is es_ES
On es_ES, the list separator is semi-colon. So, "1024,768".split(";") returns "1024,768" and then the try to convert to int crashes but the message is confuse, because 1024,768 is a valid number on Spanish.
Expected behavior
Try to convert "1024,768" when regional settings are es_ES throws an exception with a message like:
"Unable to create a Size from '1024,768' string because it was not possible to extract the required two components using the separator ';' from culture 'es_ES'"
Actual behavior
Try to convert "1024,768" when regional settings are es_ES throws an exception because 1024,768 is not a valid integer
Regression?
No response
Known Workarounds
On Windows modify the regional settings to use "," as list separator instead ";"
Configuration
No response
Other information
No response