dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

`[AllowedValues]` and `[DeniedValues]` case insensitivness suport #98399

Open BachiMjavanadze opened 9 months ago

BachiMjavanadze commented 9 months ago

I think it would be better if the [AllowedValues] and [Denied Values] attributes had support for case insensitivity. So instead:

[AllowedValues("bad", "Bad", "bAd", "baD", "BAD")]

or defining custom attribute, possible to write this:

[AllowedValues("bad" CaseInsensitive = true)]

ghost commented 8 months ago

Tagging subscribers to this area: @dotnet/area-system-componentmodel-dataannotations See info in area-owners.md if you want to be subscribed.

Issue Details
I think it would be better if the `[AllowedValues]` and `[Denied Values]` attributes had support for case insensitivity. So instead: `[AllowedValues("bad", "Bad", "bAd", "baD", "BAD")]` or defining custom attribute, possible to write this: `[AllowedValues("bad" CaseInsensitive = true)]`
Author: BachiMjavanadze
Assignees: -
Labels: `area-System.ComponentModel.DataAnnotations`, `untriaged`
Milestone: -
eiriktsarpalis commented 8 months ago

The attributes work on arbitrary values, not just strings. A general-purpose API would necessitate passing an IEqualityComparer parameter, however that typically doesn't work with attribute annotations -- you would need to manually define one via inheritance.

BachiMjavanadze commented 8 months ago

Ok!