Exemple #1
0
 public static void IsNotNullOrEmpty(INotNullObject obj, string objectName)
 {
     if (obj == null)
     {
         throw new ArgumentNullException(objectName);
     }
     if (obj.IsEmpty())
     {
         throw new ArgumentException(objectName + " 不能为empty", objectName);
     }
 }
Exemple #2
0
        protected override void Validate(DomainObject domainObject, DomainProperty property, object propertyValue, ValidationResult result)
        {
            if (propertyValue == null)
            {
                AddError(property, result);
                return;
            }

            INotNullObject notNullObj = propertyValue as INotNullObject;

            if (notNullObj != null)
            {
                if (notNullObj.IsEmpty())
                {
                    AddError(property, result);
                }
                return;
            }

            if (property.PropertyType == typeof(string))
            {
                var stringValue = (string)propertyValue;
                if (string.IsNullOrEmpty(stringValue))
                {
                    AddError(property, result);
                }
                return;
            }

            if (property.PropertyType.IsList())
            {
                var listValue = (IList)propertyValue;
                if (listValue.Count == 0)
                {
                    AddError(property, result);
                }
                return;
            }


            if (DataUtil.IsPrimitiveType(property.PropertyType))
            {
                if (DataUtil.IsDefaultValue(propertyValue))
                {
                    AddError(property, result);
                }
                return;
            }
        }