예제 #1
0
 public static DateTimeField WhenHasValueShould(this NullableField <DateTime> field)
 {
     if (field.Value.HasValue)
     {
         return(new DateTimeField(field.Value.Value, true).UseDisplayName(field.DisplayName));
     }
     else
     {
         return(new DateTimeField(DateTime.MinValue, false).UseDisplayName(field.DisplayName));
     }
 }
예제 #2
0
 public static Int32Field WhenHasValueShould(this NullableField <int> field)
 {
     if (field.Value.HasValue)
     {
         return(new Int32Field(field.Value.Value, true).UseDisplayName(field.DisplayName));
     }
     else
     {
         return(new Int32Field(int.MinValue, false).UseDisplayName(field.DisplayName));
     }
 }
예제 #3
0
 public static DecimalField WhenHasValueShould(this NullableField <decimal> field)
 {
     if (field.Value.HasValue)
     {
         return(new DecimalField(field.Value.Value, true).UseDisplayName(field.DisplayName));
     }
     else
     {
         return(new DecimalField(decimal.MinValue, false).UseDisplayName(field.DisplayName));
     }
 }
예제 #4
0
        /// <summary>
        /// 验证不允许为空
        /// </summary>
        /// <typeparam name="TInnerValue"></typeparam>
        /// <param name="field"></param>
        /// <param name="customMsg">自定义错误信息,为空时忽略</param>
        /// <returns></returns>
        public static NullableField <TInnerValue> NotBeNull <TInnerValue>(this NullableField <TInnerValue> field,
                                                                          string customMsg = "") where TInnerValue : struct
        {
            if (field.ShouldValidate)
            {
                if (!field.Value.HasValue)
                {
                    throw new ValidationException(string.IsNullOrEmpty(customMsg) ?
                                                  string.Format("{0}:不允许为空!", field.DisplayName) : customMsg);
                }
            }

            return(field);
        }