The Labs \ Source Viewer \ SSCLI \ System.Configuration \ StringValidatorAttribute

  1. //------------------------------------------------------------------------------
  2. // <copyright file="StringValidatorAttribute.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. using System;
  16. using System.Configuration.Internal;
  17. using System.Collections;
  18. using System.Collections.Specialized;
  19. using System.Collections.Generic;
  20. using System.IO;
  21. using System.Reflection;
  22. using System.Security.Permissions;
  23. using System.Xml;
  24. using System.Globalization;
  25. using System.ComponentModel;
  26. using System.Security;
  27. using System.Text;
  28. namespace System.Configuration
  29. {
  30.    
  31.     [AttributeUsage(AttributeTargets.Property)]
  32.     public sealed class StringValidatorAttribute : ConfigurationValidatorAttribute
  33.     {
  34.         private int _minLength = 0;
  35.         private int _maxLength = int.MaxValue;
  36.         private string _invalidChars;
  37.        
  38.         public StringValidatorAttribute()
  39.         {
  40.         }
  41.        
  42.         public override ConfigurationValidatorBase ValidatorInstance {
  43.             get { return new StringValidator(_minLength, _maxLength, _invalidChars); }
  44.         }
  45.        
  46.         public int MinLength {
  47.             get { return _minLength; }
  48.             set {
  49.                 if (_maxLength < value) {
  50.                     throw new ArgumentOutOfRangeException("value", SR.GetString(SR.Validator_min_greater_than_max));
  51.                 }
  52.                
  53.                 _minLength = value;
  54.             }
  55.         }
  56.        
  57.         public int MaxLength {
  58.             get { return _maxLength; }
  59.             set {
  60.                 if (_minLength > value) {
  61.                     throw new ArgumentOutOfRangeException("value", SR.GetString(SR.Validator_min_greater_than_max));
  62.                 }
  63.                
  64.                 _maxLength = value;
  65.             }
  66.         }
  67.        
  68.         public string InvalidCharacters {
  69.             get { return _invalidChars; }
  70.             set { _invalidChars = value; }
  71.         }
  72.     }
  73. }

Developer Fusion