class status fixes
[mono.git] / mcs / class / System.Web / System.Web.UI / CollectionBuilder.cs
1 //
2 // System.Web.UI.CollectionBuilder.cs
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (c) 2003 Ximian, Inc. (http://www.ximian.com)
8 //
9
10 using System;
11 using System.Collections;
12 using System.Reflection;
13
14 namespace System.Web.UI
15 {
16         sealed class CollectionBuilder : ControlBuilder
17         {
18                 Type elementType;
19
20                 internal CollectionBuilder ()
21                 {
22                 }
23
24                 public override void AppendLiteralString (string s)
25                 {
26                         if (s != null && s.Trim () != "")
27                                 throw new HttpException ("Literal content not allowed for " + ControlType);
28                 }
29
30                 public override Type GetChildControlType (string tagName, IDictionary attribs)
31                 {
32                         Type t = Root.GetChildControlType (tagName, attribs);
33                         if (elementType != null && !elementType.IsAssignableFrom (t)) 
34                                 throw new HttpException ("Cannot add a " + t + " to " + elementType);
35
36                         return t;
37                 }
38
39                 public override void Init (TemplateParser parser,
40                                            ControlBuilder parentBuilder,
41                                            Type type,
42                                            string tagName,
43                                            string id,
44                                            IDictionary attribs)
45                 {
46                         base.Init (parser, parentBuilder, type, tagName, id, attribs);
47
48                         PropertyInfo prop = parentBuilder.ControlType.GetProperty (tagName, flagsNoCase);
49                         SetControlType (prop.PropertyType);
50
51                         prop = ControlType.GetProperty ("Item", flagsNoCase & ~BindingFlags.IgnoreCase);
52                         elementType = prop.PropertyType;
53                 }
54         }
55 }
56