我创建了如下所示的日期范围属性:
[DateRange(Min = "Today")]
在这个属性中,我得到这样的最小日期:
...
var minDate = DateTime.Now;
...
编辑:这里有更多代码:
private DateTime _minDate = DateTime.Today.AddYears(-100);
private DateTime _maxDate = DateTime.MaxValue;
// String representation of the Min Date (yyyy/MM/dd)
public string Min
{
get { return FormatDate(_minDate, DateTime.Today.AddYears(-100)); }
set { _minDate = value == "Today" ? DateTime.Today : ParseDate(value, DateTime.Today.AddYears(-100)); }
}
// String representation of the Max Date (yyyy/MM/dd)
public string Max
{
get { return FormatDate(_maxDate, DateTime.MaxValue); }
set { _maxDate = value == "Today" ? DateTime.Today : ParseDate(value, DateTime.MaxValue); }
}
由于属性的性质,minDate 在编译时只设置一次。你能告诉我实现这个功能的替代方法吗?