Table of Contents

Class CustomRule

Namespace
Apq.Cfg.Validation.Rules
Assembly
Apq.Cfg.dll

自定义验证规则

public sealed class CustomRule : IValidationRule
Inheritance
CustomRule
Implements
Inherited Members

Constructors

CustomRule(string, Func<string?, bool>, string, string?)

创建自定义验证规则

public CustomRule(string key, Func<string?, bool> validator, string errorMessage, string? ruleName = null)

Parameters

key string

配置键

validator Func<string, bool>

验证函数,返回 true 表示验证通过

errorMessage string

错误消息

ruleName string

规则名称

Properties

ErrorMessage

错误消息

public string ErrorMessage { get; }

Property Value

string

Key

要验证的配置键

public string Key { get; }

Property Value

string

Name

规则名称

public string Name { get; }

Property Value

string

Methods

Validate(string?)

验证配置值

public ValidationError? Validate(string? value)

Parameters

value string

配置值

Returns

ValidationError

验证错误,如果验证通过返回 null