Есть классы
public class MyDateValidationAttribute : ValidationAttribute
{
public object DateToCompare { get; set; }
public bool IsValueMore { get; set; }
public override bool IsValid(object value)
{
var e = Convert.ToDateTime(DateToCompare);
DateTime d = Convert.ToDateTime(value);
return (IsValueMore ? d >= e : d <= e);
}
}
[Serializable]
public class ViewModel
{
[Display(ResourceType = typeof(AdminResource), Name = "Admin_Report_StartDate")]
[ReportSummary(itemOrder: 1, format: ReportColumnFormat.Date)]
[MyDateValidation(ErrorMessage ="Start date can't be greater than end date", IsValueMore = false**, DateToCompare = End**]
public DateTime? Start { get; set; }
[Display(ResourceType = typeof(AdminResource), Name = "Admin_Report_EndDate")]
[ReportSummary(itemOrder: 2, format: ReportColumnFormat.Date)]
[MyDateValidation(ErrorMessage = "Start date can't be greater than end date", IsValueMore = false, **DateToCompare = Start**))]
public DateTime? End { get; set; }
}
Нужно валидировать End дата больше Start дата для корректной query в сервисе.
Сложность с передачей параметра DateToCompare в класс аттрибута, не знаю как это сделать. Ошибка следующая -
object reference is required for the non-static field attribute.
Прошу совета
Продвижение своими сайтами как стратегия роста и независимости