public static DataValidateResult Validate <T>(T t) { Type tType = typeof(T); DataValidateResult dataValidate = new DataValidateResult { IsSuccess = true, ResultString = "OK" }; foreach (var item in tType.GetProperties()) { if (item.IsDefined(typeof(BaseValidateAttribute), true)) { var attribute = (item.GetCustomAttributes(typeof(BaseValidateAttribute), true)[0]) as BaseValidateAttribute; if (!attribute.Validate(item.GetValue(t))) { dataValidate.IsSuccess = false; if (attribute.GetType().IsDefined(typeof(ErrorStringAttribute), true)) { dataValidate.ResultString = ((attribute.GetType().GetCustomAttributes(typeof(ErrorStringAttribute), true)[0]) as ErrorStringAttribute).ErrorMessage; } else { dataValidate.ResultString = "数据输入不合法"; } break; } } } return(dataValidate); }
public void Validate() { ValidateResult.Clear(); if (Column.Validator != null) { DataValidateResult validateResult = Column.Validator.Validate(Value); if (!validateResult.IsValid) { ValidateResult.Merge(validateResult); } } }
public ExcelSheetCell(ExcelSheetColumn column) { Column = column; Value = string.Empty; ValidateResult = new DataValidateResult(); }
public ExcelSheetRow() { Cells = new List <ExcelSheetCell>(); RowLevelValidateResult = new DataValidateResult(); }