Files
“wanyongkang” ed3b2c653e 接口文件
2024-04-10 13:55:27 +08:00

55 lines
1.3 KiB
C#

using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Hncore.Infrastructure.Data;
namespace Hncore.Infrastructure.Common
{
public class CheckHelper
{
public static void NotNull(object obj, string message = "")
{
if (ReferenceEquals(obj, null))
{
if (string.IsNullOrEmpty(message))
{
message = nameof(obj) + "空引用";
}
throw new BusinessException(message);
}
}
public static void NotEmpty(string obj, string message = "")
{
NotNull(obj,message);
if (obj.Trim() == "")
{
if (string.IsNullOrEmpty(message))
{
message = nameof(obj) + "值不能为空";
}
throw new BusinessException(message);
}
}
}
public static class Ext
{
public static void Check(this ModelStateDictionary dic)
{
if (!dic.IsValid)
{
var errs = dic.Values.SelectMany(x => x.Errors);
string msg = "";
errs.Select(t => t.Exception.Message).ToList().ForEach((s => { msg += s + "\r\n"; }));
throw new Exception(msg);
}
}
}
}