Skip to content
Advertisement

Is there any data validation nuget library like python’s voluptuous in C#? [closed]

For data validation, Python coders frequently will use this library called Voluptuous. Is a great library to validate data before processing it further in the code.

Is there any equivalent NuGet library we can use in C#?

Below is a python snippet on how to use voluptuous in python

from voluptuous import Required, All, Length, Range
schema = Schema({
   Required('q'): All(str, Length(min=1)),
   Required('per_page', default=5): All(int, Range(min=1, max=20)), 'page': All(int, Range(min=0))
})

Advertisement

Answer

I’m unsure how well it pairs to Voluptuous (I’m not a user of Python at all), but FluentValidation is a library that I like and use often. It’s pretty flexible and has met my needs easily so far.

There is also the option of using the native data annotations, but this is less flexible and couples things too closely for my personal liking. I use these only in very rare cases.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement