Class RequiredValidator
- Namespace
- BootstrapBlazor.Components
- Assembly
- BootstrapBlazor.dll
Required 验证实现类
public class RequiredValidator : ValidatorBase, IValidator
- Inheritance
-
RequiredValidator
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
RequiredValidator()
public RequiredValidator()
Properties
AllowEmptyString
获得/设置 是否允许空字符串 默认 false 不允许
public bool AllowEmptyString { get; set; }
Property Value
ErrorMessage
获得/设置 错误描述信息 默认为 null 需要赋值
public string? ErrorMessage { get; set; }
Property Value
LocalizerFactory
获得/设置 IStringLocalizerFactory 注入服务实例 默认为 null
public IStringLocalizerFactory? LocalizerFactory { get; set; }
Property Value
Options
获得/设置 Json 资源文件配置 默认为 null
public JsonLocalizationOptions? Options { get; set; }
Property Value
Methods
GetLocalizerErrorMessage(ValidationContext, IStringLocalizerFactory?, JsonLocalizationOptions?)
通过资源文件获取 ErrorMessage 方法
protected virtual string? GetLocalizerErrorMessage(ValidationContext context, IStringLocalizerFactory? localizerFactory = null, JsonLocalizationOptions? options = null)
Parameters
context
ValidationContextlocalizerFactory
IStringLocalizerFactoryoptions
JsonLocalizationOptions
Returns
GetRuleKey()
获得当前验证规则资源文件中 Key 格式
protected virtual string GetRuleKey()
Returns
Validate(object?, ValidationContext, List<ValidationResult>)
验证方法
public override void Validate(object? propertyValue, ValidationContext context, List<ValidationResult> results)
Parameters
propertyValue
object待校验值
context
ValidationContextValidateContext 实例
results
List<ValidationResult>ValidateResult 集合实例