Skip to content

Exception when passing "0" to CountryProvider TryParse method #61

@hot-lightning

Description

@hot-lightning

When passing a numerical value as a string (like "0"), to Enum.TryParse(), it will resolve the member with the numerical value, or one that is not explicitly defined.

In the CountryProvider.TryGetCountry method, the Enum.TryParse is used to determine whether or not a country code exists in the specific set.
The xmldoc on this method suggests it should never throw an exception when a non-existing country code is passed in, but return false (with null value for ICountryInfo)

Suggestion: use Enum.IsDefined before Enum.Tryparse and return false when the string does not correspond to any enum member.

Btw, I believe this behaviour changed since this commit : 2a7616d
(because before that, it returned AF as the zero value member)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions