/// <summary> /// get error value /// </summary> /// <param name="baseValidation"></param> /// <returns></returns> public static object GetErrorValue(BaseValidationRuleInfoAttribute baseValidation) { if (baseValidation is IValidationRuleInfoAttribute validationRuleInfoAttribute) { return(validationRuleInfoAttribute.GetErrorValue()); } else { MethodInfo getErrorValueMethod = baseValidation.GetType().FindMethod("GetErrorValue"); if (getErrorValueMethod == null) { throw new Exception($"GetErrorValue method not found! are you shure you inheritance IValidationRuleInfoAttribute or IValidationRuleInfoAttribute<T> on your attribute {baseValidation.GetType().FullName}"); } object state = baseValidation.GetType().GetProperty("LastStateChecked", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(baseValidation, null); return(getErrorValueMethod.Invoke(baseValidation, new object[] { state })); } }
/// <summary> /// check if validation data is validate /// </summary> /// <param name="baseValidation"></param> /// <returns></returns> public static bool CheckIsValidate(BaseValidationRuleInfoAttribute baseValidation) { if (baseValidation is IValidationRuleInfoAttribute validationRuleInfoAttribute) { return(validationRuleInfoAttribute.CheckIsValidate()); } else { MethodInfo checkIsValidateMethod = baseValidation.GetType().FindMethod("CheckIsValidate"); if (checkIsValidateMethod == null) { throw new Exception($"CheckIsValidate method not found! are you shure you inheritance IValidationRuleInfoAttribute or IValidationRuleInfoAttribute<T> on your attribute {baseValidation.GetType().FullName}"); } object state = checkIsValidateMethod.Invoke(baseValidation, null); baseValidation.LastStateChecked = state; MethodInfo checkStateIsSuccessMethod = baseValidation.GetType().FindMethod("CheckStateIsSuccess"); if (checkStateIsSuccessMethod == null) { throw new Exception($"CheckStateIsSuccess method not found! are you shure you inheritance IValidationRuleInfoAttribute<T> on your attribute {baseValidation.GetType().FullName}"); } return((bool)checkStateIsSuccessMethod.Invoke(baseValidation, new object[] { state })); } }