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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CallbackValidator.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.Collections;
  17. using System.IO;
  18. using System.Reflection;
  19. using System.Security.Permissions;
  20. using System.Xml;
  21. using System.Collections.Specialized;
  22. using System.Globalization;
  23. using System.ComponentModel;
  24. using System.Security;
  25. using System.Text;
  26. using System.Text.RegularExpressions;
  27. namespace System.Configuration
  28. {
  29.    
  30.     public sealed class CallbackValidator : ConfigurationValidatorBase
  31.     {
  32.         Type _type;
  33.         ValidatorCallback _callback;
  34.        
  35.         public CallbackValidator(Type type, ValidatorCallback callback) : this(callback)
  36.         {
  37.             if (type == null) {
  38.                 throw new ArgumentNullException("type");
  39.             }
  40.             _type = type;
  41.         }
  42.        
  43.         // Do not check for null type here to handle the callback attribute case
  44.         internal CallbackValidator(ValidatorCallback callback)
  45.         {
  46.             if (callback == null) {
  47.                 throw new ArgumentNullException("callback");
  48.             }
  49.             _type = null;
  50.             _callback = callback;
  51.         }
  52.        
  53.         public override bool CanValidate(Type type)
  54.         {
  55.             return (type == _type || _type == null);
  56.         }
  57.         public override void Validate(object value)
  58.         {
  59.             _callback(value);
  60.         }
  61.     }
  62. }

Developer Fusion