12345678910111213141516171819202122232425262728293031 |
- using System;
- namespace Wayne.Lib
- {
- public static class ParamGuard
- {
- public static void AssertIsNotNull<T>(T paramValue, string paramName) where T : class
- {
- if (paramValue == null)
- {
- throw new ArgumentNullException(paramName);
- }
- }
- public static void AssertMeetsCondition<T>(T paramValue, Func<T, bool> paramChecker, string paramName, string conditionName)
- {
- if (!paramChecker(paramValue))
- {
- throw new ArgumentException(string.Format("Parameter {0} does not meet condition {1} ", paramName, conditionName));
- }
- }
- public static void AssertNotNullOrEmpty(string paramValue, string paramName)
- {
- if (string.IsNullOrEmpty(paramValue))
- {
- throw new ArgumentException(string.Format("Parameter {0} is null or empty ", paramName));
- }
- }
- }
- }
|