Wed Feb 24 15:47:16 CET 2010 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI / ParseChildrenAttribute.cs
1 //
2 // System.Web.UI.ParseChildrenAttribute.cs
3 //
4 // Authors:
5 //      Duncan Mak  (duncan@ximian.com)
6 //      Gonzalo Paniagua (gonzalo@ximian.com)
7 //
8 // (C) 2002 Ximian, Inc. (http://www.ximian.com
9 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using System.Security.Permissions;
32
33 namespace System.Web.UI {
34
35         // CAS - no InheritanceDemand here as the class is sealed
36         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37         // attributes
38         [AttributeUsage (AttributeTargets.Class)]
39         public sealed class ParseChildrenAttribute : Attribute
40         {
41                 bool childrenAsProperties;
42                 string defaultProperty;
43                 public static readonly ParseChildrenAttribute Default = new ParseChildrenAttribute ();
44                 public static readonly ParseChildrenAttribute ParseAsChildren = new ParseChildrenAttribute (false);
45                 public static readonly ParseChildrenAttribute ParseAsProperties = new ParseChildrenAttribute (true);
46
47                 Type childType = typeof(System.Web.UI.Control);
48
49                 // LAMESPEC
50                 public ParseChildrenAttribute ()
51                 {
52                         childrenAsProperties = false;
53                         defaultProperty = "";
54                 }
55
56                 public ParseChildrenAttribute (bool childrenAsProperties)
57                 {
58                         this.childrenAsProperties = childrenAsProperties;
59                         this.defaultProperty = "";
60                 }
61
62                 public ParseChildrenAttribute (bool childrenAsProperties,
63                                                string defaultProperty)
64                 {
65                         this.childrenAsProperties = childrenAsProperties;
66                         if (childrenAsProperties)
67                                 this.defaultProperty = defaultProperty;
68                 }
69
70                 public ParseChildrenAttribute (Type childControlType)
71                 {
72                         childType = childControlType;
73                         defaultProperty = "";
74                 }
75
76                 public bool ChildrenAsProperties {
77
78                         get { return childrenAsProperties; }
79
80                         set { childrenAsProperties = value; }
81                 }
82
83                 public string DefaultProperty {
84                         get { return defaultProperty; }
85
86                         set { defaultProperty = value; }
87                 }
88
89                 public Type ChildControlType {
90                         get { return childType; }
91                 }
92
93                 public override bool Equals (object obj)
94                 {
95                         ParseChildrenAttribute o = (obj as ParseChildrenAttribute);
96                         if (o == null)
97                                 return false;
98
99                         if (childrenAsProperties == o.childrenAsProperties){
100                                 if (childrenAsProperties == false)
101                                         return true;
102                                 return (defaultProperty == o.DefaultProperty);
103                         }
104                         return false;
105                 }
106
107                 public override int GetHashCode ()
108                 {
109                         return base.GetHashCode ();
110                 }
111
112                 public override bool IsDefaultAttribute ()
113                 {
114                         return Equals (Default);
115                 }
116         }
117 }