public IEnumerable <ValidationResult> Validate(string instanceName, bool isRequired = false) { var result = new List <ValidationResult>(); if (DateFrom.YearMax == DateTime.Now.Year) { result.AddRange(DateFrom.ValidatePastDate($"{instanceName}.{nameof(DateFrom)}", true)); } else { result.AddRange(DateFrom.Validate($"{instanceName}.{nameof(DateFrom)}", true)); } if (DateTo.YearMax == DateTime.Now.Year) { result.AddRange(DateTo.ValidatePastDate($"{instanceName}.{nameof(DateTo)}", DateToRequired)); } else { result.AddRange(DateTo.Validate($"{instanceName}.{nameof(DateTo)}", DateToRequired)); } if ((DateToRequired || !DateTo.IsEmpty()) && (DateTo.ToDate() < DateFrom.ToDate())) { result.Add(new ValidationResult(string.Empty, new[] { $"{instanceName}.{nameof(DateTo)}" })); } return(result); }