刘磊
2025-04-19 823752496e2a4cdb6a1fb36227cd15b8b7135336
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using Masuit.Tools;
using System.ComponentModel.DataAnnotations;
 
namespace WIDESEA_StorageBasicService;
 
public class Dt_InWheels_mes_htyService : ServiceBase<Dt_InWheels_mes_hty, IDt_InWheels_mes_htyRepository>, IDt_InWheels_mes_htyService
{
    public Dt_InWheels_mes_htyService(IDt_InWheels_mes_htyRepository BaseDal) : base(BaseDal)
    {
    }
 
    // 验证模型
    public static List<ValidationResult> ValidateModel(object model)
    {
        // 创建一个验证结果列表
        var validationResults = new List<ValidationResult>();
        // 创建一个验证上下文
        var validationContext = new ValidationContext(model, serviceProvider: null, items: null);
 
        // 使用验证器尝试验证模型,并将验证结果添加到验证结果列表中
        Validator.TryValidateObject(model, validationContext, validationResults, validateAllProperties: true);
 
        // 返回验证结果列表
        return validationResults;
    }
}