IDataErrorInfo vs IValidatableObject?

寵の児 提交于 2019-12-04 02:59:45

问题


Currently my business objects implement IDataErrorInfo. Since I intend to use these libraries in ASP.NET MVC 3, I figure I should implement IValidatableObject as well or maybe instead of.

Does WPF work with IValidatableObject?

How do DataAnnotations fit into the picture?


回答1:


IValidatableObject is an interface for verifying whole object level errors. It is your responsibility to implemts it by verifying data annotations or other techniques. MVC has native support for data annotations so you can just use them without any further support.

On the contrary wpf ONLY SUPPORTS IDataErrorInfo. It has no support for IValidateObject or DataAnnotations.

However I implemented a wrapper object that add DataAnnotation support in Wpf to the wrapped object. It furnishes also an implementation of IPropertyChanged. See the Validation Toolkit for Wpf and Silverlight on codeplex




回答2:


I am implementing IValidatableObject at entity, wrapping it with IDataErrorInfo at view model (automatically via base class) for WPF. My entities will work well in either WPF, MVC and new EF CTP5 who also honors IValidatableObject.



来源:https://stackoverflow.com/questions/4233920/idataerrorinfo-vs-ivalidatableobject

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