SqlSugar\Src\Asp.Net\SqlSugar\Utilities\Check.cs
功能:SqlSugar异常处理静态函数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public class Check
{
/// <summary>
/// 根据传入字符串抛出UtilException
/// </summary>
/// <param name="message">空字符串抛出默认NotSupportedException,非空则根据message抛出UtilExceptions</param>
public static void ThrowNotSupportedException(string message)
{
message = message.IsNullOrEmpty() ? new NotSupportedException().Message : message;
throw new UtilExceptions("SqlSugarException.NotSupportedException:" + message);
}
/// <summary>
/// 根据传入的checkObj和message判断
/// 如果checkObj为空则抛出UtilException,并用message填充
/// </summary>
/// <param name="checkObj">待判断Obj</param>
/// <param name="message">异常填充message字符串</param>
public static void ArgumentNullException(object checkObj, string message)
{
if (checkObj == null)
throw new UtilExceptions("SqlSugarException.ArgumentNullException:" + message);
}
/// <summary>
/// 判断传入checkObj数组是否为空
/// </summary>
/// <param name="checkObj">传入Obj数组</param>
/// <param name="message">异常填充字符串</param>
public static void ArgumentNullException(object [] checkObj, string message)
{
//checkOjb是否为空或者checkOjb数组成员为0
if (checkObj == null || checkObj.Length==0)
throw new UtilExceptions("SqlSugarException.ArgumentNullException:" + message);
}
/// <summary>
/// 根据参数判断并抛出UtilExceptions
/// </summary>
/// <param name="isException">是否Exception标记变量</param>
/// <param name="message">异常Message</param>
/// <param name="args">异常Message格式化参数</param>
public static void Exception(bool isException, string message, params string[] args)
{
if (isException)
throw new UtilExceptions(string.Format(message, args));
}
}
}
网友评论