public ValidationResult Validate(dynamic target) { ValidationResult validationResult; try { // check type support if (RuleContainer.GetInstance().CheckRuleSupportingType(GetType(), target.GetType()) == false) { validationResult = new ValidationResult(false, string.Format("Rule {0} không hỗ trợ cho kiểu dữ liệu {1}", GetType(), target.GetType())); return(validationResult); } if (CheckValid(target) == false) { validationResult = new ValidationResult(false, errorMessage); } else { validationResult = new ValidationResult(true, ""); } } catch (Exception e) { validationResult = new ValidationResult(false, e.Message); } return(validationResult); }
protected override void AddSupportType() { List <Type> types = new List <Type>(); types.AddRange(Utility.NumericTypes); types.AddRange(Utility.StringTypes); RuleContainer.GetInstance().AddSupportType(GetType(), types); }
public static RuleContainer GetInstance() { if (instance == null) { instance = new RuleContainer(); } return(instance); }
protected override void AddSupportType() { RuleContainer.GetInstance().AddSupportType(GetType(), Utility.StringTypes); }