通过每个属性我正在使用simplemvvmtoolkit进行验证(INotifyDataErrorInfo)。而不是我重复自己一遍又一遍的视图模型中的每个属性,Id喜欢使用反射来获取所有属性并验证它们,但我似乎无法弄清楚在validateProperty方法中传递什么。使用反射来获取所有属性并通过方法
private void ValidateInput()
{
var unitProperties = this.GetType().GetProperties()
.Where(x => x.CanRead);
foreach (var prop in unitProperties)
ValidateProperty(prop, prop.GetValue(this, null)); //????
//?^get errors here
}
ValidateProperty发生在:
protected virtual void ValidateProperty<TResult>(Expression<Func<TViewModel, TResult>> property, object value);
如果”已经实现了INotifyDataErrorInfo,你不能只为每个属性名称调用GetErrors(name)方法吗? – RogerN 2013-04-24 18:09:55