b4f92594884e3cc19de1a181d8d12a4de7b68574
[mono.git] / mcs / class / referencesource / mscorlib / system / reflection / __filters.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 ////////////////////////////////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////////////////////////////////
8 //
9 // <OWNER>Microsoft</OWNER>
10 // 
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.
14 //
15 //  
16 //  
17 //
18 namespace System.Reflection {
19     using System;
20     using System.Globalization;
21     //<
22
23
24
25     [Serializable]
26     internal class __Filters {
27         
28         // FilterTypeName 
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)
32         {
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"));
36     
37             String str = (String) filterCriteria;
38             //str = str.Trim();
39     
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);
44             }
45     
46             return cls.Name.Equals(str);
47         }
48         
49         // FilterFieldNameIgnoreCase
50         // This method filter the Type based upon name, it ignores case.
51         public virtual bool FilterTypeNameIgnoreCase(Type cls, Object filterCriteria)
52         {
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"));
56     
57             String str = (String) filterCriteria;
58             //str = str.Trim();
59     
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);
66                 else
67                     return false;
68             }
69             return (String.Compare(str,cls.Name, StringComparison.OrdinalIgnoreCase) == 0);
70         }
71     }
72 }