Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type of IEnumerable should INotifyDataErrorInfo.GetErrors return?

It blows my mind that the official document at MSDN doesn't say anything about what the underlying object type of the enumerable that returned by GetErrors of INotifyDataErrorInfo should be: http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo.geterrors(v=vs.95).aspx

Options are: System.String, System.Object, MyCustomObject, ISomeOtherShitThatDoesntHaveAnythingToDoWithValidationWhatsoever

Can anybody explain to me how an arbitrary enumerable of object can be OK for notifying about errors without making any assumptions about its structure?

like image 736
Trident D'Gao Avatar asked Nov 20 '12 13:11

Trident D'Gao


1 Answers

The docs for INotifyDataErrorInfo give more information:

The validation errors returned by the GetErrors method can be of any type. However, if you implement a custom error type, be sure to override the ToString method to return an error message. Silverlight uses this string in its default error reporting.

Custom error objects are useful when you provide custom error reporting in the user interface. For example, you can create a template for the reporting ToolTip that binds to an ErrorLevel property in order to display warnings in yellow and critical errors in red.

There's a link in the Examples section of GetErrors back to that documentation:

For an example of an implementation of this method, see the INotifyDataErrorInfo class overview.

I agree it's less clear than it might be, but the documentation is there...

like image 50
Jon Skeet Avatar answered Nov 09 '22 10:11

Jon Skeet