MustBeTrueAttribute.cs 499 B

1234567891011121314151617
  1. using System.ComponentModel.DataAnnotations;
  2. namespace bitforum.Attributes
  3. {
  4. public class MustBeTrueAttribute : ValidationAttribute
  5. {
  6. protected override ValidationResult IsValid(object? value, ValidationContext validationContext)
  7. {
  8. if (value is bool boolValue && boolValue)
  9. {
  10. return ValidationResult.Success;
  11. }
  12. return new ValidationResult(ErrorMessage ?? "값은 `true` 여야 합니다.");
  13. }
  14. }
  15. }