[bcl] Remove NET_2_0 defines from the class libs. This has been done using: unifdef...
[mono.git] / mcs / class / System.Configuration / System.Configuration / StringValidator.cs
index 4f701530e853235732a7cf28e2b5a90ae3f95de7..1b737b7e642d6f55088c11376b6f8411e34be572 100644 (file)
@@ -26,8 +26,6 @@
 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
 //
 
-#if NET_2_0
-
 namespace System.Configuration
 {
        public class StringValidator: ConfigurationValidatorBase
@@ -63,18 +61,19 @@ namespace System.Configuration
 
                public override void Validate (object value)
                {
+                       if (value == null && minLength <= 0)
+                               return;
+
                        string s = (string) value;
-                       if (s.Length < minLength)
-                               throw new ConfigurationErrorsException ("Invalid string length. The minimun length is " + minLength + ".");
+                       if (s == null || s.Length < minLength)
+                               throw new ArgumentException ("The string must be at least " + minLength + " characters long.");
                        if (s.Length > maxLength)
-                               throw new ConfigurationErrorsException ("Invalid string length. The maximim length is " + maxLength + ".");
+                               throw new ArgumentException ("The string must be no more than " + maxLength + " characters long.");
                        if (invalidCharacters != null) {
                                int i = s.IndexOfAny (invalidCharacters);
                                if (i != -1)
-                                       throw new ConfigurationErrorsException ("The character '" + s[i] + "' is not allowed in this attribute.");
+                                       throw new ArgumentException (String.Format ("The string cannot contain any of the following characters: '{0}'.", invalidCharacters));
                        }
                }
        }
 }
-
-#endif