Exemple #1
0
        /// <summary>
        /// 是否合规判断方法
        /// </summary>
        /// <param name="value"></param>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        protected override ValidationResult?IsValid(object?value, ValidationContext validationContext)
        {
            ValidationResult?ret = null;

            if (value != null)
            {
                var file = (IBrowserFile?)value;
                if (file != null)
                {
                    Localizer = JsonStringLocalizerFactory.CreateLocalizer <Upload <object> >();
                    if (Extensions.Any() && !Extensions.Contains(Path.GetExtension(file.Name), StringComparer.OrdinalIgnoreCase))
                    {
                        var errorMessage = Localizer?["FileExtensions", string.Join(", ", Extensions)];
                        ret = new ValidationResult(errorMessage?.Value, new[] { validationContext.MemberName ! });
 /// <summary>
 /// 构造函数
 /// </summary>
 public FileValidationAttribute()
 {
     Localizer = JsonStringLocalizerFactory.CreateLocalizer <Upload>();
 }