The Labs \ Source Viewer \ SSCLI \ System.Reflection \ __Filters

  1. // ==++==
  2. //
  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. //
  14. // ==--==
  15. ////////////////////////////////////////////////////////////////////////////////
  16. ////////////////////////////////////////////////////////////////////////////////
  17. //
  18. // This class defines the delegate methods for the COM+ implemented filters.
  19. // This is the reflection version of these. There is also a _Filters class in
  20. // runtime which is related to this.
  21. //
  22. //
  23. //
  24. //
  25. namespace System.Reflection
  26. {
  27.     using System;
  28.     using System.Globalization;
  29.     [Serializable()]
  30.     internal class __Filters
  31.     {
  32.        
  33.         // FilterTypeName
  34.         // This method will filter the class based upon the name. It supports
  35.         // a trailing wild card.
  36.         public virtual bool FilterTypeName(Type cls, object filterCriteria)
  37.         {
  38.             // Check that the criteria object is a String object
  39.             if (filterCriteria == null || !(filterCriteria is string))
  40.                 throw new InvalidFilterCriteriaException(System.Environment.GetResourceString("RFLCT.FltCritString"));
  41.            
  42.             string str = (string)filterCriteria;
  43.             //str = str.Trim();
  44.            
  45.             // Check to see if this is a prefix or exact match requirement
  46.             if (str.Length > 0 && str[str.Length - 1] == '*') {
  47.                 str = str.Substring(0, str.Length - 1);
  48.                 return cls.Name.StartsWith(str, StringComparison.Ordinal);
  49.             }
  50.            
  51.             return cls.Name.Equals(str);
  52.         }
  53.        
  54.         // FilterFieldNameIgnoreCase
  55.         // This method filter the Type based upon name, it ignores case.
  56.         public virtual bool FilterTypeNameIgnoreCase(Type cls, object filterCriteria)
  57.         {
  58.             // Check that the criteria object is a String object
  59.             if (filterCriteria == null || !(filterCriteria is string))
  60.                 throw new InvalidFilterCriteriaException(System.Environment.GetResourceString("RFLCT.FltCritString"));
  61.            
  62.             string str = (string)filterCriteria;
  63.             //str = str.Trim();
  64.            
  65.             // Check to see if this is a prefix or exact match requirement
  66.             if (str.Length > 0 && str[str.Length - 1] == '*') {
  67.                 str = str.Substring(0, str.Length - 1);
  68.                 string name = cls.Name;
  69.                 if (name.Length >= str.Length)
  70.                     return (String.Compare(name, 0, str, 0, str.Length, StringComparison.OrdinalIgnoreCase) == 0);
  71.                 else
  72.                     return false;
  73.             }
  74.             return (String.Compare(str, cls.Name, StringComparison.OrdinalIgnoreCase) == 0);
  75.         }
  76.     }
  77. }

Developer Fusion