internal IReadOnlyCollection <string> GetErrorMessages(string propertyName) { var propertyValidation = _propertyValidations.SingleOrDefault(f => f.PropertyName == propertyName); if (propertyValidation == null) { HasErrors = false; return(new List <string>()); } var propertyValue = _viewModel.GetType().GetProperty(propertyName)?.GetValue(_viewModel); var errorMessages = propertyValidation.GetValidationErrorMessages(propertyValue); HasErrors = errorMessages.Any(); return(errorMessages); }
public static string YearValidation(ValidatableViewModel viewmodel, string propertyname) { var propValue = viewmodel.GetType().GetProperty(propertyname).GetValue(viewmodel, null); if (propValue != null) { string stringPropValue = propValue.ToString(); int result; if (int.TryParse(stringPropValue, out result)) { if (result > 1900 && result < 2100) { return null; } } } return "wrong year!"; }