Validation framework in C#?

ⅰ亾dé卋堺 提交于 2019-12-09 18:11:19

问题


In the java world there is the bean validation framework JSR-303 which is a nicely well thought out strategy for performing data validation in both the presentation and persistence layers of an application. It covers a lot of things, including validation of whole graph models, validation domain grouping, i18n, etc.

I have failed to find any data model validation frameworks in C#. Are there anything similar to JSR-303 in C#?


回答1:


There is the Enterprise Library Validation block. http://msdn.microsoft.com/en-us/library/ff648831.aspx

It may not do some of the specific items you are asking about (i18n) out of the box, but it fits the bill for many other use cases.

Also, is free to use and has source code available.




回答2:


You can try fluent validation:

http://fluentvalidation.codeplex.com/




回答3:


On the front end:

The web side (asp.net) has Validation controls for web forms, and Validation Helpers for MVC. Both of these are smart enough to know how to render validation logic to the client page (for faster failure responses and reduced server load) and duplicate the necessary logic server-side (since you can't trust the client).

The Windows side has Error Providers for winforms. I'm not sure about WPF/Silverlight, or if there's anything for Console apps.

The result is that things are a little fragmented, but not so bad that you can't quickly find what you need. The idea is find the approach that's best for each platform, rather than shoehorning different platforms to the same set of principles.

On the back end, you can use the Enterprise Validation Application Block.




回答4:


There is also the data annotations that can help with client and server side validation: http://msdn.microsoft.com/en-us/library/ee256141.aspx



来源:https://stackoverflow.com/questions/8159234/validation-framework-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!