Exemplo n.º 1
0
 internal StringLengthValidatorInfo(UIImpactStringLengthConstraint constraint) : this(constraint.MinLength, constraint.MaxLength)
 {
 }
Exemplo n.º 2
0
 private void SetConstraintsFromType(Type propertyType, PropertyDefinitionConstraint[] constraints)
 {
     if (propertyType.IsGenericType)
     {
         if (propertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
         {
             propertyType = propertyType.GetGenericArguments()[0];
         }
         Type[] genericArguments = propertyType.GetGenericArguments();
         if (genericArguments.Length == 1 && !genericArguments[0].IsGenericParameter)
         {
             propertyType = genericArguments[0];
         }
     }
     if (this.IsMaskExpressionEnable())
     {
         if (typeof(short) == propertyType || typeof(int) == propertyType || typeof(long) == propertyType)
         {
             this.SetMaskExpression(this.CreateMaskExpressionForSignedNumericField(constraints));
         }
         else if (typeof(ushort) == propertyType || typeof(uint) == propertyType || typeof(ulong) == propertyType || typeof(ByteQuantifiedSize) == propertyType || typeof(EnhancedTimeSpan) == propertyType)
         {
             this.SetMaskExpression("[0-9]");
         }
         FieldInfo field = propertyType.GetField("AllowedCharacters");
         if (null != field && field.FieldType == typeof(string))
         {
             this.SetMaskExpression((string)field.GetValue(null));
         }
         if (string.IsNullOrEmpty(this.GetMaskExpression()))
         {
             StringBuilder stringBuilder = new StringBuilder("[^");
             foreach (PropertyDefinitionConstraint propertyDefinitionConstraint in constraints)
             {
                 CharacterConstraint characterConstraint = propertyDefinitionConstraint as CharacterConstraint;
                 if (characterConstraint != null)
                 {
                     if (characterConstraint.ShowAsValid)
                     {
                         this.SetMaskExpression(characterConstraint.Pattern);
                         break;
                     }
                     stringBuilder.Append(characterConstraint.Pattern.Substring(2, characterConstraint.Pattern.Length - 3));
                 }
             }
             if (string.IsNullOrEmpty(this.GetMaskExpression()) && stringBuilder.Length > 2)
             {
                 this.SetMaskExpression(stringBuilder.Append(']').ToString());
             }
         }
     }
     if (this.IsMaxLengthEnable())
     {
         int num = this.IsInvalidChar('-') ? -1 : 0;
         if (typeof(short) == propertyType || typeof(ushort) == propertyType)
         {
             this.SetMaxLength(short.MinValue.ToString().Length + num);
         }
         else if (typeof(int) == propertyType || typeof(uint) == propertyType)
         {
             this.SetMaxLength(int.MinValue.ToString().Length + num);
         }
         else if (typeof(long) == propertyType || typeof(ulong) == propertyType || typeof(ByteQuantifiedSize) == propertyType || typeof(EnhancedTimeSpan) == propertyType)
         {
             this.SetMaxLength(long.MinValue.ToString().Length + num);
         }
         FieldInfo fieldInfo = null;
         Type      type      = propertyType;
         while (null != type && null == fieldInfo)
         {
             fieldInfo = type.GetField("MaxLength");
             type      = type.BaseType;
         }
         if (null != fieldInfo && fieldInfo.FieldType == typeof(int))
         {
             this.SetMaxLength((int)fieldInfo.GetValue(null));
         }
         foreach (PropertyDefinitionConstraint propertyDefinitionConstraint2 in constraints)
         {
             UIImpactStringLengthConstraint uiimpactStringLengthConstraint = propertyDefinitionConstraint2 as UIImpactStringLengthConstraint;
             if (uiimpactStringLengthConstraint != null)
             {
                 this.SetMaxLength(uiimpactStringLengthConstraint.MaxLength);
                 return;
             }
             StringLengthConstraint stringLengthConstraint = propertyDefinitionConstraint2 as StringLengthConstraint;
             if (stringLengthConstraint != null)
             {
                 this.SetMaxLength(stringLengthConstraint.MaxLength);
                 return;
             }
         }
     }
 }