C#的中括号意思[DateTimeRange]public DateTime?PostTime{get{return _PostTime;}set{if (_PostTime = value){_PostTime = value;OnPropertyChanged("PostTime");}}}//public class DateTimeRange :ValidationAttribute{public override bool IsValid(object valu

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 14:29:04
C#的中括号意思[DateTimeRange]publicDateTime?PostTime{get{return_PostTime;}set{if(_PostTime=value){_PostTim

C#的中括号意思[DateTimeRange]public DateTime?PostTime{get{return _PostTime;}set{if (_PostTime = value){_PostTime = value;OnPropertyChanged("PostTime");}}}//public class DateTimeRange :ValidationAttribute{public override bool IsValid(object valu
C#的中括号意思
[DateTimeRange]
public DateTime?PostTime
{
get
{
return _PostTime;
}
set
{
if (_PostTime = value)
{
_PostTime = value;
OnPropertyChanged("PostTime");
}
}
}
//
public class DateTimeRange :ValidationAttribute
{
public override bool IsValid(object value)
{
var datetime = value as DateTime?;
if (datetime.HasValue && datetime.Value > DateTime.Today)
return false;
return true;
}
public override string FormatErrorMessage(string name)
{
return "输入的时间超出范围!";
}
}
第一行中括号的用法及意义

C#的中括号意思[DateTimeRange]public DateTime?PostTime{get{return _PostTime;}set{if (_PostTime = value){_PostTime = value;OnPropertyChanged("PostTime");}}}//public class DateTimeRange :ValidationAttribute{public override bool IsValid(object valu
[DateTimeRange] 添加C#特性
public class DateTimeRange :ValidationAttribute 使得 DateTimeRange 继承了 ValidationAttribute 所以现在 DataTimeRange特性就具有了自定义验证功能