예제 #1
0
 public static void IsNotNull(object argument, string argumentName, string message = "")
 {
     if (argument == null)
     {
         var ex = new ArgumentNullEx(argumentName, message);
         LogerHelp.Error(ex);
         throw ex;
     }
 }
예제 #2
0
 public static void IsNotNegative(float argument, string argumentName)
 {
     if (argument < 0)
     {
         var ex = new ArgumentOutOfRangeException(argumentName);
         LogerHelp.Error(ex);
         throw ex;
     }
 }
예제 #3
0
 public static void IsNotEmpty(string argument, string argumentName)
 {
     if (string.IsNullOrEmpty((argument ?? string.Empty).Trim()))
     {
         var ex = new ArgumentException(string.Format("\"{0}\" 不能为空.", argumentName), argumentName);
         LogerHelp.Error(ex);
         throw ex;
     }
 }
예제 #4
0
 public static void IsNotOutOfLength(string argument, int length, string argumentName)
 {
     if (argument.Trim().Length > length)
     {
         var ex = new ArgumentException(string.Format("\"{0}\" 不能超过 {1} 字符.", argumentName, length), argumentName);
         LogerHelp.Error(ex);
         throw ex;
     }
 }
예제 #5
0
 public static void IsNotOutOfRange(int argument, int min, int max, string argumentName)
 {
     if ((argument < min) || (argument > max))
     {
         var ex = new ArgumentOutOfRangeException(argumentName, string.Format("{0} 必须在此区间 \"{1}\"-\"{2}\".", argumentName, min, max));
         LogerHelp.Error(ex);
         throw ex;
     }
 }
예제 #6
0
 public static void IsNotEmpty(Guid argument, string argumentName)
 {
     if (argument == Guid.Empty)
     {
         var ex = new ArgumentException(string.Format("\"{0}\" 不能为空Guid.", argumentName), argumentName);
         LogerHelp.Error(ex);
         throw ex;
     }
 }
예제 #7
0
 public static void IsNotNegativeOrZero(TimeSpan argument, string argumentName)
 {
     if (argument <= TimeSpan.Zero)
     {
         var ex = new ArgumentOutOfRangeException(argumentName);
         LogerHelp.Error(ex);
         throw ex;
     }
 }
예제 #8
0
 public static void IsNotInFuture(DateTime argument, string argumentName)
 {
     if (argument > DateTime.Now)
     {
         var ex = new ArgumentOutOfRangeException(argumentName);
         LogerHelp.Error(ex);
         throw ex;
     }
 }
예제 #9
0
            public static void IsNotExistsDirectory(string argument, string argumentName)
            {
                IsNotEmpty(argument, argumentName);

                if (!Directory.Exists(argument))
                {
                    var ex = new ArgumentException(string.Format("\"{0}\" 目录不存在", argumentName), argumentName);
                    LogerHelp.Error(ex);
                    throw ex;
                }
            }
예제 #10
0
            public static void IsNotEmpty <T>(ICollection <T> argument, string argumentName)
            {
                IsNotNull(argument, argumentName, "集合不能为Null");

                if (argument.Count == 0)
                {
                    var ex = new ArgumentException("集合不能为空.", argumentName);
                    LogerHelp.Error(ex);
                    throw ex;
                }
            }
예제 #11
0
            public static void IsNotInvalidDate(DateTime argument, string argumentName)
            {
                DateTime MinDate = new DateTime(1900, 1, 1);
                DateTime MaxDate = new DateTime(9999, 12, 31, 23, 59, 59, 999);

                if (!((argument >= MinDate) && (argument <= MaxDate)))
                {
                    var ex = new ArgumentOutOfRangeException(argumentName);
                    LogerHelp.Error(ex);
                    throw ex;
                }
            }