how to set compile time validation on class instance members

跟風遠走 提交于 2019-12-02 02:31:16

It's experimental, but you could look into Spec#. It can provide you with more compile-time checks. Code Contracts are another option (but that's only available in certain editions of Visual Studio).

Edit:

Looks like code contacts may now be available as a standalone download! See this page!

You don't have that out-of-the-box in .NET, but there're some validation engines that let you validate an instance of some object against some rules.

Read about:

I'll suggest you to use NHValidator, because it's very easy-to-use, needs zero configuration and it has a good community support. Another good point is you can use in any layer (business, presentation...) because it's attribute-oriented, meaning that you don't need to inherit any class or implement an interface in order to use it anywhere!

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