public static string ValidateProperty(this ValidationViewModelBase dp, string propertyName) { if (string.IsNullOrEmpty(propertyName)) { return(string.Empty); } var targetType = dp.GetType(); var propertyValue = targetType.GetProperty(propertyName).GetValue(dp, null); return(dp.ValidateProperty(propertyValue, propertyName)); }
public static bool ValidateViewModel(this ValidationViewModelBase dp) { string strValid = string.Empty; var props = dp.GetType() .GetProperties() .Where(p => ((ValidationAttribute[])p.GetCustomAttributes(typeof(ValidationAttribute), true)).Length != 0); foreach (PropertyInfo item in props) { var value = item.GetValue(dp, null); strValid = dp.ValidateProperty(value, item.Name); dp.NotityProperChanged(item.Name); if (strValid != string.Empty) { return(false); } } return(true); }
public static string ValidateProperty <MetadataType>(this ValidationViewModelBase dp, string propertyName) { if (string.IsNullOrEmpty(propertyName)) { return(string.Empty); } var targetType = dp.GetType(); if (targetType != typeof(MetadataType)) { TypeDescriptor.AddProviderTransparent( new AssociatedMetadataTypeTypeDescriptionProvider(targetType, typeof(MetadataType)), targetType); } var propertyValue = targetType.GetProperty(propertyName).GetValue(dp, null); return(dp.ValidateProperty(propertyValue, propertyName)); }