Check.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using Abp.Collections.Extensions;
  5. using Abp.Extensions;
  6. using JetBrains.Annotations;
  7. namespace Abp
  8. {
  9. [DebuggerStepThrough]
  10. public static class Check
  11. {
  12. [ContractAnnotation("value:null => halt")]
  13. public static T NotNull<T>(T value, [InvokerParameterName] [NotNull] string parameterName)
  14. {
  15. if (value == null)
  16. {
  17. throw new ArgumentNullException(parameterName);
  18. }
  19. return value;
  20. }
  21. [ContractAnnotation("value:null => halt")]
  22. public static string NotNullOrEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
  23. {
  24. if (value.IsNullOrEmpty())
  25. {
  26. throw new ArgumentException($"{parameterName} can not be null or empty!", parameterName);
  27. }
  28. return value;
  29. }
  30. [ContractAnnotation("value:null => halt")]
  31. public static string NotNullOrWhiteSpace(string value, [InvokerParameterName] [NotNull] string parameterName)
  32. {
  33. if (value.IsNullOrWhiteSpace())
  34. {
  35. throw new ArgumentException($"{parameterName} can not be null, empty or white space!", parameterName);
  36. }
  37. return value;
  38. }
  39. [ContractAnnotation("value:null => halt")]
  40. public static ICollection<T> NotNullOrEmpty<T>(ICollection<T> value, [InvokerParameterName] [NotNull] string parameterName)
  41. {
  42. if (value.IsNullOrEmpty())
  43. {
  44. throw new ArgumentException(parameterName + " can not be null or empty!", parameterName);
  45. }
  46. return value;
  47. }
  48. }
  49. }