As per the "Remarks" section from the documentation: MSDN: INotifyDataErrorInfo Interface
This interface enables data entity classes to implement custom
validation rules and expose validation results asynchronously. This
interface also supports custom error objects, multiple errors per
property, cross-property errors, and entity-level errors.
Cross-property errors are errors that affect multiple properties. You
can associate these errors with one or all of the affected properties,
or you can treat them as entity-level errors. Entity-level errors are
errors that either affect multiple properties or affect the entire
entity without affecting a particular property.
I might suggest that the implementation of GetErrors
is highly dependent upon your error handling scheme. If, for instance, you do not intend to support Entity-Level
errors, then your example code is sufficient. If, however, you do need to support Entity-Level
errors, then you may handle the IsNullOrEmpty
condition separately:
Public IEnumerable GetErrors(String propertyName)
{
if (String.IsNullOrEmpty(propertyName))
return entity_errors;
if (!property_errors.ContainsKey(propertyName))
return null;
return property_errors[propertyName];
}