【发布时间】:2018-08-17 20:25:24
【问题描述】:
我想用 possharp 开发一个 NotifyDataErrorInfoAspect。
值的验证取决于几个可变属性(MinValue、MaxValue ...)。合约不能使用可变参数。
我想构建类似于 DependencyPropertyAspect 的东西。 [DependencyProperty] 的每个属性都有许多可选方法。例如 ValidatePropertyName。
[DependencyProperty]
public string Email { get; set; }
private bool ValidateEmail(string value)
{
return EmailRegex.IsMatch(value);
}
我该怎么做?
[NotifyDataErrorInfo]
public string Name{ get; set; }
private IList<DataErrorInfo> ValidateName(string value)
{
return this.IsValidName(value);
}
[NotifyDataErrorInfo]
public int Age{ get; set; }
private IList<DataErrorInfo> ValidateAge(int value)
{
return this.IsValidAge(value);
}
[NotifyDataErrorInfo]
public string Email { get; set; }
private IList<DataErrorInfo> ValidateEmail(string value)
{
return this.IsValidEmail(value);
}
属性 ImportMethod() 只允许固定的方法名。 最好的方法是什么?
【问题讨论】: