Example #1
0
        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);
        }
Example #2
0
        public void Validate()
        {
            ValidateResult.Clear();

            if (Column.Validator != null)
            {
                DataValidateResult validateResult = Column.Validator.Validate(Value);
                if (!validateResult.IsValid)
                {
                    ValidateResult.Merge(validateResult);
                }
            }
        }
Example #3
0
 public ExcelSheetCell(ExcelSheetColumn column)
 {
     Column         = column;
     Value          = string.Empty;
     ValidateResult = new DataValidateResult();
 }
Example #4
0
 public ExcelSheetRow()
 {
     Cells = new List <ExcelSheetCell>();
     RowLevelValidateResult = new DataValidateResult();
 }