コード例 #1
0
 /// <summary>
 /// 检查键值对是否为空
 /// </summary>
 /// <typeparam name="TKey"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void CheckNull <TKey, TValue>(this KeyValuePair <TKey, TValue> argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentNullException>(
         !string.IsNullOrWhiteSpace(argument.ToString()),
         argumentName, message ?? $"{nameof(argument)} contains nothing.");
 }
コード例 #2
0
 /// <summary>
 /// 检查字符串是否为 null、String.Empty 或 Blank
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void CheckNull(this string argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentNullException>(
         !string.IsNullOrWhiteSpace(argument),
         argumentName, $"{nameof(argument)} can not be null or white space.");
 }
コード例 #3
0
 /// <summary>
 /// 检查时间是否为未来
 /// <para>如果是未来,则抛出异常</para>
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotInFuture(DateTime argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentOutOfRangeException>(
         argument <= DateTime.UtcNow,
         argumentName, argument, message ?? $"{nameof(argument)} can not be in future.");
 }
コード例 #4
0
 /// <summary>
 /// 检查时间间隔是否为负
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotNegative(TimeSpan argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentOutOfRangeException>(
         argument >= TimeSpan.Zero,
         argumentName, argument, message ?? $"{nameof(argument)} can not be negative.");
 }
コード例 #5
0
 /// <summary>
 /// 检查整数是否越界
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="min"></param>
 /// <param name="max"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotOutOfRange(int argument, int min, int max, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentOutOfRangeException>(
         NumericJudgment.IsBetween(argument, min, max),
         argumentName, argument, message ?? $"{nameof(argument)} is not between {min} and {max}.");
 }
コード例 #6
0
 /// <summary>
 /// 检查时间是否合法
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotInvalidDate(DateTime argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentException>(
         DateTimeJudgment.IsValid(argument),
         message ?? $"{nameof(argument)} is invalid datetime value.", argumentName);
 }
コード例 #7
0
 /// <summary>
 /// 检查字符串是否为 Blank
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotEmpty(string argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentNullException>(
         !string.IsNullOrWhiteSpace((argument ?? string.Empty).Trim()),
         argumentName, message ?? $"{nameof(argument)} can not be blank.");
 }
コード例 #8
0
 /// <summary>
 /// 检查整数是否为非正数
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotNegativeOrZero(int argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentOutOfRangeException>(
         argument > 0,
         argumentName, argument, message ?? $"{nameof(argument)} can not be negative or zero.");
 }
コード例 #9
0
 /// <summary>
 /// 检查 Guid 是否为空
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotEmpty(Guid argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentNullException>(
         !GuidJudgment.IsNullOrEmpty(argument),
         argumentName, message ?? $"{nameof(argument)} can not be null or empty.");
 }
コード例 #10
0
 /// <summary>
 /// 检查集合至少包含多少个元素
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="number"></param>
 /// <param name="message"></param>
 public static void IsAtLeast <T>(ICollection <T> argument, string argumentName, int number, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentOutOfRangeException>(
         CollectionJudgment.ContainsAtLeast(argument, number),
         argumentName, argument.Count, message ?? $"{nameof(argument)} should has {number} items at least.");
 }
コード例 #11
0
 /// <summary>
 /// 检查集合是否为空
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotNull(IEnumerable argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentNullException>(
         !CollectionJudgment.IsNull(argument),
         argumentName, message ?? $"{nameof(argument)} can not be null.");
 }
コード例 #12
0
 /// <summary>
 /// 检查对象是否为空
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotNull(object argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentNullException>(
         argument != null,
         argumentName, message ?? $"{nameof(argument)} can not be null.");
 }
コード例 #13
0
 /// <summary>
 /// 检查字符串长度是否超界
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="length"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotOutOfLength(string argument, int length, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentOutOfRangeException>(
         argument.Trim().Length <= length,
         argumentName, argument.Trim().Length, message ?? $"{nameof(argument)}'s length can not be greater than {length}.");
 }