我正在使用 simplemvvmtoolkit 进行验证(INotifyDataErrorInfo)。我不想为视图模型中的每个属性一遍又一遍地重复我自己,我喜欢使用反射来获取所有属性并验证它们,但我似乎无法弄清楚在 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);