The Labs \ Source Viewer \ SSCLI \ System.Net \ TimeoutValidator

  1. //------------------------------------------------------------------------------
  2. // <copyright file="TimeoutValidator.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Net
  16. {
  17.     using System;
  18.     using System.Configuration;
  19.     using System.ComponentModel;
  20.    
  21.     internal sealed class TimeoutValidator : ConfigurationValidatorBase
  22.     {
  23.         bool _zeroValid = false;
  24.        
  25.         internal TimeoutValidator(bool zeroValid)
  26.         {
  27.             _zeroValid = zeroValid;
  28.         }
  29.        
  30.         public override bool CanValidate(Type type)
  31.         {
  32.             return (type == typeof(int) || type == typeof(long));
  33.         }
  34.        
  35.         public override void Validate(object value)
  36.         {
  37.             if (value == null)
  38.                 return;
  39.            
  40.             int timeout = (int)value;
  41.            
  42.             if (_zeroValid && timeout == 0)
  43.                 return;
  44.            
  45.             if (timeout <= 0 && timeout != System.Threading.Timeout.Infinite) {
  46.                 throw new ConfigurationErrorsException(SR.GetString(SR.net_io_timeout_use_gt_zero));
  47.             }
  48.         }
  49.     }
  50. }

Developer Fusion