// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
-#if NET_2_0
-
namespace System.Configuration
{
public class StringValidator: ConfigurationValidatorBase
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