2 // System.Web.UI.FilterableAttribute
5 // Sanjay Gupta (gsanjay@novell.com)
7 // (C) 2004 Novell, Inc. (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.ComponentModel;
34 namespace System.Web.UI {
35 [AttributeUsage (AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
36 public sealed class FilterableAttribute : Attribute
38 private bool filterable;
40 public FilterableAttribute (bool filterable)
42 this.filterable = filterable;
45 public static readonly FilterableAttribute Default = new FilterableAttribute (true);
47 public static readonly FilterableAttribute No = new FilterableAttribute (false);
49 public static readonly FilterableAttribute Yes = new FilterableAttribute (true);
51 public bool Filterable {
52 get { return filterable; }
55 public override bool Equals (object obj)
57 if (obj != null && obj is FilterableAttribute) {
58 FilterableAttribute fa = (FilterableAttribute) obj;
59 return (this.filterable == fa.filterable);
64 public override int GetHashCode ()
66 return this.filterable.GetHashCode ();
69 public override bool IsDefaultAttribute ()
71 return Equals (Default);
74 public static bool IsObjectFilterable (object obj)
76 return IsTypeFilterable (obj.GetType ());
79 public static bool IsPropertyFilterable (PropertyDescriptor propDesc)
81 System.ComponentModel.AttributeCollection attributes = propDesc.Attributes;
82 if (attributes.Count != 0) {
83 foreach (Attribute attrib in attributes)
84 if (attrib is FilterableAttribute)
90 public static bool IsTypeFilterable (Type type)
92 Object [] attributes = type.GetCustomAttributes (typeof (FilterableAttribute), false);
93 if (attributes.Length != 0) {
94 foreach (Attribute attrib in attributes)
95 if (attrib is FilterableAttribute)