Error.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  2. using System;
  3. using System.Runtime.CompilerServices;
  4. namespace Cysharp.Threading.Tasks.Internal
  5. {
  6. internal static class Error
  7. {
  8. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  9. public static void ThrowArgumentNullException<T>(T value, string paramName)
  10. where T : class
  11. {
  12. if (value == null) ThrowArgumentNullExceptionCore(paramName);
  13. }
  14. [MethodImpl(MethodImplOptions.NoInlining)]
  15. static void ThrowArgumentNullExceptionCore(string paramName)
  16. {
  17. throw new ArgumentNullException(paramName);
  18. }
  19. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  20. public static Exception ArgumentOutOfRange(string paramName)
  21. {
  22. return new ArgumentOutOfRangeException(paramName);
  23. }
  24. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  25. public static Exception NoElements()
  26. {
  27. return new InvalidOperationException("Source sequence doesn't contain any elements.");
  28. }
  29. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  30. public static Exception MoreThanOneElement()
  31. {
  32. return new InvalidOperationException("Source sequence contains more than one element.");
  33. }
  34. [MethodImpl(MethodImplOptions.NoInlining)]
  35. public static void ThrowArgumentException<T>(string message)
  36. {
  37. throw new ArgumentException(message);
  38. }
  39. [MethodImpl(MethodImplOptions.NoInlining)]
  40. public static void ThrowNotYetCompleted()
  41. {
  42. throw new InvalidOperationException("Not yet completed.");
  43. }
  44. [MethodImpl(MethodImplOptions.NoInlining)]
  45. public static T ThrowNotYetCompleted<T>()
  46. {
  47. throw new InvalidOperationException("Not yet completed.");
  48. }
  49. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  50. public static void ThrowWhenContinuationIsAlreadyRegistered<T>(T continuationField)
  51. where T : class
  52. {
  53. if (continuationField != null) ThrowInvalidOperationExceptionCore("continuation is already registered.");
  54. }
  55. [MethodImpl(MethodImplOptions.NoInlining)]
  56. static void ThrowInvalidOperationExceptionCore(string message)
  57. {
  58. throw new InvalidOperationException(message);
  59. }
  60. [MethodImpl(MethodImplOptions.NoInlining)]
  61. public static void ThrowOperationCanceledException()
  62. {
  63. throw new OperationCanceledException();
  64. }
  65. }
  66. }