command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

Extend `AcceptOnlyFromAmong` with `bool ignoreCase = false`

Open adamsitnik opened this issue 2 years ago • 2 comments

Context: https://github.com/dotnet/format/issues/1797#issuecomment-1653018175

adamsitnik avatar Jul 31 '23 12:07 adamsitnik

Case-insensitive Enum.Parse uses OrdinalIgnoreCase comparison, rather than culture-dependent: https://github.com/dotnet/runtime/blob/a08d9ce2caf02455c0b825bcdc32974bdf769a80/src/libraries/System.Private.CoreLib/src/System/Enum.cs#L921

KalleOlaviNiemitalo avatar Jul 31 '23 14:07 KalleOlaviNiemitalo

After thinking about this a bit more, I'm not sure the solution proposed in this issue title is the best approach. The core of the problem is that the validation and the parsing have different casing rules. If the API could ensure they're aligned, it would be less error-prone without having to add complexity. On the other hand, making this configurable could open the door to the opposite inconsistency, e.g. someone has case-sensitive parsing but case-insensitive validation.

We're redesigning the validation APIs and we should consider this in the redesign.

jonsequitur avatar Jul 31 '23 17:07 jonsequitur