You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.9 KiB

2 years ago
  1. using System;
  2. using Newtonsoft.Json;
  3. namespace SqlSugar
  4. {
  5. public class UtilExceptions : Exception
  6. {
  7. public UtilExceptions(string message)
  8. : base(message){}
  9. public UtilExceptions(SqlSugarClient context,string message, string sql)
  10. : base(GetMessage(context, message, sql)) {}
  11. public UtilExceptions(SqlSugarClient context, string message, string sql, object pars)
  12. : base(GetMessage(context,message, sql, pars)){}
  13. public UtilExceptions(SqlSugarClient context, string message, object pars)
  14. : base(GetMessage(context,message, pars)){}
  15. private static string GetMessage(SqlSugarClient context, string message, object pars)
  16. {
  17. var parsStr = string.Empty; ;
  18. if (pars != null)
  19. {
  20. parsStr = context.Utilities.SerializeObject(pars);
  21. }
  22. var reval = GetLineMessage(nameof(message), message) + GetLineMessage("function", parsStr);
  23. return reval;
  24. }
  25. private static string GetMessage(SqlSugarClient context, string message, string sql, object pars)
  26. {
  27. if (pars == null)
  28. {
  29. return GetMessage(context,message, sql);
  30. }
  31. else
  32. {
  33. var reval = GetLineMessage("message ", message) + GetLineMessage("ORM Sql", sql) + GetLineMessage("函数参数 ", JsonConvert.SerializeObject(pars));
  34. return reval;
  35. }
  36. }
  37. private static string GetMessage(string message, string sql)
  38. {
  39. var reval = GetLineMessage("message ", message) + GetLineMessage("ORM Sql", sql);
  40. return reval;
  41. }
  42. private static string GetLineMessage(string key, string value)
  43. {
  44. return string.Format("{0} : '{1}' \r\n", key, value);
  45. }
  46. }
  47. }