|
|
@ -1,14 +1,15 @@ |
|
|
using System.ComponentModel.DataAnnotations; |
|
|
using System; |
|
|
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
using System.Reflection; |
|
|
using System.Reflection; |
|
|
|
|
|
|
|
|
namespace Volo.Abp.AspNetCore.Mvc.Validation; |
|
|
namespace Volo.Abp.AspNetCore.Mvc.Validation; |
|
|
|
|
|
|
|
|
public static class ValidationAttributeHelper |
|
|
public static class ValidationAttributeHelper |
|
|
{ |
|
|
{ |
|
|
private static readonly PropertyInfo ValidationAttributeErrorMessageStringProperty = typeof(ValidationAttribute) |
|
|
private readonly static PropertyInfo ValidationAttributeErrorMessageStringProperty = typeof(ValidationAttribute) |
|
|
.GetProperty("ErrorMessageString", BindingFlags.Instance | BindingFlags.NonPublic)!; |
|
|
.GetProperty("ErrorMessageString", BindingFlags.Instance | BindingFlags.NonPublic)!; |
|
|
|
|
|
|
|
|
private static readonly PropertyInfo ValidationAttributeCustomErrorMessageSetProperty = typeof(ValidationAttribute) |
|
|
private readonly static PropertyInfo ValidationAttributeCustomErrorMessageSetProperty = typeof(ValidationAttribute) |
|
|
.GetProperty("CustomErrorMessageSet", BindingFlags.Instance | BindingFlags.NonPublic)!; |
|
|
.GetProperty("CustomErrorMessageSet", BindingFlags.Instance | BindingFlags.NonPublic)!; |
|
|
|
|
|
|
|
|
public static void SetDefaultErrorMessage(ValidationAttribute validationAttribute) |
|
|
public static void SetDefaultErrorMessage(ValidationAttribute validationAttribute) |
|
|
@ -24,7 +25,14 @@ public static class ValidationAttributeHelper |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
validationAttribute.ErrorMessage = |
|
|
try |
|
|
ValidationAttributeErrorMessageStringProperty.GetValue(validationAttribute) as string; |
|
|
{ |
|
|
|
|
|
var errorMessageString = ValidationAttributeErrorMessageStringProperty.GetValue(validationAttribute) as string; |
|
|
|
|
|
validationAttribute.ErrorMessage = errorMessageString; |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception e) |
|
|
|
|
|
{ |
|
|
|
|
|
// ignored
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|