3 using System.Configuration;
4 using System.ComponentModel;
6 // NOTE [Microsoft]: The old validation attribute was removed from System.ll and is
7 // replaced by more flexible and robust validation/conversion design.
8 // The change bellow is a simple fix to make things work with the least possible change ( it is an integration break )
9 // However, we already have a built-in support for configuration properties that store
10 // Type names. We do reccomend that all uses of the validator bellow are converted to
11 // properties of type Type ( instead of string ) which use the TypeNameConverter from System.Configuration.dll
12 // Feel free to ask me for more details if you decide to do the conversion
13 internal sealed class TimeoutValidator : ConfigurationValidatorBase
15 bool _zeroValid = false;
17 internal TimeoutValidator(bool zeroValid) {
18 _zeroValid = zeroValid;
21 public override bool CanValidate( Type type ) {
22 return ( type == typeof( int ) || type == typeof( long ) );
25 public override void Validate( object value ) {
29 int timeout = (int)value;
31 if (_zeroValid && timeout == 0)
34 if (timeout <= 0 && timeout != System.Threading.Timeout.Infinite) {
35 // Note [Microsoft] : This is a lab integration fix. Old code did not have any error message at this point
36 // This code change accomplishes the same result. However its highly reccomended that a specific error message is givven
37 // to the user so they know what exaclty is the problem ( i.e. the value must be a positive integer or be Infinite )
38 // To accomplish this - an exception with the specific error message could be thrown ( ArgumentException is prefferred )
39 throw new ConfigurationErrorsException(SR.GetString(SR.net_io_timeout_use_gt_zero));