ExceptionBuilder.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Data.Common;
  3. namespace EasyDevCore.Database
  4. {
  5. /// <summary>
  6. ///
  7. /// </summary>
  8. public static class ExceptionBuilder
  9. {
  10. /// <summary>
  11. /// Transactions the error.
  12. /// </summary>
  13. /// <param name="message">The message.</param>
  14. /// <returns></returns>
  15. public static Exception TransactionError(string message)
  16. {
  17. return new Exception(message);
  18. }
  19. /// <summary>
  20. /// Nots the supported exception.
  21. /// </summary>
  22. /// <param name="message">The message.</param>
  23. /// <returns></returns>
  24. public static Exception NotSupportedException(string message = null)
  25. {
  26. return new NotSupportedException(message);
  27. }
  28. /// <summary>
  29. /// Arguments the null.
  30. /// </summary>
  31. /// <param name="message">The message.</param>
  32. /// <returns></returns>
  33. public static Exception ArgumentNull(string message = null)
  34. {
  35. return new ArgumentNullException(message);
  36. }
  37. /// <summary>
  38. /// Arguments the out of range.
  39. /// </summary>
  40. /// <param name="message">The message.</param>
  41. /// <returns></returns>
  42. public static Exception ArgumentOutOfRange(string message = null)
  43. {
  44. return new ArgumentOutOfRangeException(message);
  45. }
  46. /// <summary>
  47. /// Invalids the length of the offset.
  48. /// </summary>
  49. /// <param name="message">The message.</param>
  50. /// <returns></returns>
  51. public static Exception InvalidOffsetLength(string message = null)
  52. {
  53. return new ArgumentException(message);
  54. }
  55. /// <summary>
  56. /// Columns the out of range.
  57. /// </summary>
  58. /// <param name="index">The index.</param>
  59. /// <returns></returns>
  60. public static Exception ColumnOutOfRange(int index)
  61. {
  62. return new IndexOutOfRangeException();
  63. }
  64. /// <summary>
  65. /// Columns the not in entity.
  66. /// </summary>
  67. /// <param name="columnName">Name of the column.</param>
  68. /// <param name="entityName">Name of the entity.</param>
  69. /// <returns></returns>
  70. public static Exception ColumnNotInEntity(string columnName, string entityName)
  71. {
  72. return new ArgumentException();
  73. }
  74. /// <summary>
  75. /// Columns the out of range.
  76. /// </summary>
  77. /// <param name="index">The index.</param>
  78. /// <param name="entityName">Name of the entity.</param>
  79. /// <returns></returns>
  80. public static Exception ColumnOutOfRange(int index, string entityName)
  81. {
  82. return new ArgumentException();
  83. }
  84. /// <summary>
  85. /// Arguments the type not support.
  86. /// </summary>
  87. /// <param name="typeName">Name of the type.</param>
  88. /// <returns></returns>
  89. public static Exception ArgumentTypeNotSupport(string typeName)
  90. {
  91. return new ArgumentException(typeName);
  92. }
  93. /// <summary>
  94. /// Nots the implemented exception.
  95. /// </summary>
  96. /// <param name="message">The message.</param>
  97. /// <returns></returns>
  98. public static Exception NotImplementedException(string message = null)
  99. {
  100. return new NotImplementedException(message);
  101. }
  102. /// <summary>
  103. /// Invalids the cast exception.
  104. /// </summary>
  105. /// <param name="fromType">From type.</param>
  106. /// <param name="toType">To type.</param>
  107. /// <returns></returns>
  108. public static Exception InvalidCastException(Type fromType, Type toType)
  109. {
  110. return new InvalidCastException($"Type: {fromType.Name} not cast to {toType.Name}");
  111. }
  112. /// <summary>
  113. /// Concurrencies the exception.
  114. /// </summary>
  115. /// <param name="message">The message.</param>
  116. /// <returns></returns>
  117. public static Exception ConcurrencyException(string message)
  118. {
  119. return new ConcurrencyException(message);
  120. }
  121. }
  122. }