问题描述
我对 MSDN感到困惑例子.
目前尚不清楚如何处理和设置实体实体错误.
It's not clear how to treat and set entity realted errors.
示例代码:
public System.Collections.IEnumerable GetErrors(string propertyName)
{
if (String.IsNullOrEmpty(propertyName) ||
!errors.ContainsKey(propertyName)) return null;
return errors[propertyName];
}
但是GetErrors()的文档指出:
but documentation for GetErrors() states:
另一个示例建议仅返回字典的_errors.Values.这只是所有属性错误,但又不是实体错误.
Another example suggests just returning _errors.Values of the dictionary. And this is just all properties errors but again not entity errors.
推荐答案
按照文档中备注"部分所述: MSDN:INotifyDataErrorInfo接口
As per the "Remarks" section from the documentation: MSDN: INotifyDataErrorInfo Interface
我可能建议GetErrors
的实现高度依赖于您的错误处理方案.例如,如果您不打算支持Entity-Level
错误,那么您的示例代码就足够了.但是,如果确实需要支持Entity-Level
错误,则可以单独处理IsNullOrEmpty
条件:
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];
}
这篇关于如何正确实现INotifyDataErrorInfo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!