3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 ////////////////////////////////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////////////////////////////////
9 // <OWNER>Microsoft</OWNER>
11 // This class defines the delegate methods for the COM+ implemented filters.
12 // This is the reflection version of these. There is also a _Filters class in
13 // runtime which is related to this.
18 namespace System.Reflection {
20 using System.Globalization;
26 internal class __Filters {
29 // This method will filter the class based upon the name. It supports
30 // a trailing wild card.
31 public virtual bool FilterTypeName(Type cls,Object filterCriteria)
33 // Check that the criteria object is a String object
34 if (filterCriteria == null || !(filterCriteria is String))
35 throw new InvalidFilterCriteriaException(System.Environment.GetResourceString("RFLCT.FltCritString"));
37 String str = (String) filterCriteria;
40 // Check to see if this is a prefix or exact match requirement
41 if (str.Length > 0 && str[str.Length - 1] == '*') {
42 str = str.Substring(0, str.Length - 1);
43 return cls.Name.StartsWith(str, StringComparison.Ordinal);
46 return cls.Name.Equals(str);
49 // FilterFieldNameIgnoreCase
50 // This method filter the Type based upon name, it ignores case.
51 public virtual bool FilterTypeNameIgnoreCase(Type cls, Object filterCriteria)
53 // Check that the criteria object is a String object
54 if(filterCriteria == null || !(filterCriteria is String))
55 throw new InvalidFilterCriteriaException(System.Environment.GetResourceString("RFLCT.FltCritString"));
57 String str = (String) filterCriteria;
60 // Check to see if this is a prefix or exact match requirement
61 if (str.Length > 0 && str[str.Length - 1] == '*') {
62 str = str.Substring(0, str.Length - 1);
63 String name = cls.Name;
64 if (name.Length >= str.Length)
65 return (String.Compare(name,0,str,0,str.Length, StringComparison.OrdinalIgnoreCase)==0);
69 return (String.Compare(str,cls.Name, StringComparison.OrdinalIgnoreCase) == 0);