gpt4 book ai didi

c# - 来自类的 DataAnnotations 验证

转载 作者:太空狗 更新时间:2023-10-29 23:57:49 24 4
gpt4 key购买 nike

我在纯 C# 应用程序的项目中使用 DataAnnotations,根据 DataAnnotations 属性验证我的模型/文档的最佳方法是什么?

最佳答案

现在已构建到 C# 4 中

var result = new List<ValidationResult>();
bool valid = Validator.TryValidateObject(Vehicle, new ValidationContext(Vehicle, null, null), result);

这还将为您提供验证的详细信息。

关于c# - 来自类的 DataAnnotations 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2736097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com