ParamGuard.cs 683 B

1234567891011121314151617181920212223
  1. using System;
  2. namespace Wayne.Lib
  3. {
  4. public static class ParamGuard
  5. {
  6. public static void AssertIsNotNull<T>(T paramValue, string paramName) where T : class
  7. {
  8. if (paramValue == null)
  9. {
  10. throw new ArgumentNullException(paramName);
  11. }
  12. }
  13. public static void AssertMeetsCondition<T>(T paramValue, Func<T, bool> paramChecker, string paramName, string conditionName)
  14. {
  15. if (!paramChecker(paramValue))
  16. {
  17. throw new ArgumentException(string.Format("Parameter {0} does not meet condition {1} ", paramName, conditionName));
  18. }
  19. }
  20. }
  21. }