YFTools.DataValidation 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package YFTools.DataValidation --version 1.0.0
NuGet\Install-Package YFTools.DataValidation -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="YFTools.DataValidation" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YFTools.DataValidation --version 1.0.0
#r "nuget: YFTools.DataValidation, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install YFTools.DataValidation as a Cake Addin
#addin nuget:?package=YFTools.DataValidation&version=1.0.0

// Install YFTools.DataValidation as a Cake Tool
#tool nuget:?package=YFTools.DataValidation&version=1.0.0
  1. 支持如下校验特性
 [CaseField] // 该字段将被用作Case条件,此特性必须在Case条件前声明
 pubile int Field1 { get; set; }

 [Required] // 该字段不能为空
 pubile String Field2 { get; set; }

 [RequiredField(Case = "Field1 = 3")] // 该字段在Field1 = 3时必填
 pubile String Field3 { get; set; }

 [ValidValue(1, 3, 5)] // 该字段只能取1,3,5(仅限字符串及数值)
 pubile int Field4 { get; set; }

 [NumberRange(1.5, 3.5)] // 数值必须在1.5和3.5之间(包含边界)
 pubile double Field5 { get; set; }

 [ListContains(Min = 1, Max = 9)] // 该字段至少需要包含1个元素,最多包含9个元素
 pubile List<object> Field6 { get; set; }

 [TextLength(Min = 50, Max = 100)] // 字符串长度不能少于50,不能多于100
 pubile String Field7 { get; set; }

 [DatetimeText] // 字符串是合法的时间格式
 pubile String Field8 { get; set; }

 [Email] // 字符串是合法的Email格式
 pubile String Field9 { get; set; }

 [Mobile] // 字符串是合法的手机号码
 pubile String Field10 { get; set; }

 [UrlText] // 字符串是合法的网址(http://或https://开头,忽略大小写)
 pubile String Field11 { get; set; }

 [IdCard] // 字符串是合法的15位或18位身份证号码(不会进行真实性校验)
 pubile String Field12 { get; set; }
  1. Case条件定义

    1. 定义字符串为 左值+英文单空格+操作符+英文单空格+右值,如 Case = "Field1 = 3"
    2. 左值为 CaseField字段名,需 提前声明
    3. 右值为和 CaseFiled字段类型 相对应的判断值。
    4. 操作符有
    • = 或 ==:判断左右值相等。支持字符串、日期、数值。当类型为数值时,3与3.0将被认为相等。
    • !=:判断左右值不相等。支持字符串、日期、数值。当类型为数值时,3与3.0将被认为相等。
    • >:判断左值大于右值。支持日期、数值。
    • >=:判断左值大于等于右值。支持日期、数值。
    • <:判断左值小于右值。支持日期、数值。
    • <=:判断左值小于等于右值。支持日期、数值。
    • in:判断左值包含在右值中。支持字符串、数值。右值多个数据用 英文逗号 分隔,如 Case = "Field1 IN 1,3,5"
    • notin:判断左值不包含在右值中。支持字符串或数值。右值多个数据用 英文逗号 分隔,如 Case = "Field1 NOTIN 1,3,5"
    • is: 共计4种,分别为is true, is false, is null, is not null。当判断true或false时,左值必须可以转换为bool。
  2. 数据校验接口

public class Model : IDataValidator {
    // 类成员

    public void Verify() {
        // 实现复杂的校验逻辑。校验失败请抛出异常。
        throw new DataValidationException(msg);
    }
}
  1. 字段名称定义及报错信息定义

    1. 若该字段有 DescriptionAttribute 特性,则取该特性作为名称。否则取该字段 PropertyInfo.Name 为名称。
    2. 若校验特性中单独定义了 Message 属性,则取该属性作为报错信息。否则取默认报错信息。
  2. 校验失败 校验失败会抛出 DataValidationException 异常,需自行捕获处理。

  3. 示例

var model = InitModel(); // 获取数据Model。成员校验特性配置见上。
DataValidator.Verify(model);
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.5

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated