c#public static class ExceptionExtensions
{
public static void Throw<T>(this T model, params (Expression<Func<T, bool>> Exp, string Msg)[] exps)
{
foreach (var exp in exps)
{
model.Throw(exp.Exp, exp.Msg);
}
}
public static void Throw<T>(this T model, params (bool Flag, string Msg)[] exps)
{
foreach (var exp in exps)
{
model.Throw(exp.Flag, exp.Msg);
}
}
public static void Throw<T>(this T model, Expression<Func<T, bool>> exp, string msg, ILogger log = null)
{
var flag = exp.Compile()(model);
if (flag)
throw new ApiResultException(msg, log);
}
public static void Throw<T>(this T model, bool flag, string msg, ILogger log = null)
{
if (flag)
throw new ApiResultException(msg, log);
}
}
本文作者:宁骑
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!