2003-01-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Compilation / AspGenerator.cs
index 2094b47aa33b832cab7b4bbcd25831f4b1bb44f2..8aebca2408759595ea186742458bd5c6922a9802 100644 (file)
@@ -42,6 +42,7 @@ class ControlStack
                public StringBuilder dataBindFunction;
                public StringBuilder codeRenderFunction;
                public bool useCodeRender;
+               public int codeRenderIndex;
 
                public ControlStackData (Type controlType,
                                         string controlID,
@@ -226,6 +227,12 @@ class ControlStack
                }
        }
 
+       public int CodeRenderIndex {
+               get {
+                       return top.codeRenderIndex++;
+               }
+       }
+       
        public StringBuilder CodeRenderFunction
        {
                get {
@@ -570,12 +577,16 @@ class AspGenerator
        {
                // First try loaded assemblies, then try assemblies in Bin directory.
                // By now i do this 'by hand' but may be this is a runtime/gac task.
-               Type type = Type.GetType (typeName);
-               if (type != null)
-                       return type;
+               Type type = null;
+               Assembly [] assemblies = AppDomain.CurrentDomain.GetAssemblies ();
+               foreach (Assembly ass in assemblies) {
+                       type = ass.GetType (typeName);
+                       if (type != null)
+                               return type;
+               }
 
-               string [] binDlls = Directory.GetFiles (privateBinPath, "*.dll");
                Assembly assembly;
+               string [] binDlls = Directory.GetFiles (privateBinPath, "*.dll");
                foreach (string dll in binDlls) {
                        string dllPath = Path.Combine (privateBinPath, dll);
                        assembly = null;
@@ -699,7 +710,6 @@ class AspGenerator
                        switch (data.result) {
                        case UserControlResult.OK:
                                AddUsing ("ASP");
-                               string dll = "output" + Path.DirectorySeparatorChar + data.assemblyName + ".dll";
                                Foundry.RegisterFoundry (tag_prefix, tag_name, data.assemblyName, "ASP", data.className);
                                AddReference (data.assemblyName);
                                break;
@@ -904,17 +914,19 @@ class AspGenerator
                controls.Push (control_type, control_id, tag_id, children_kind, defaultPropertyName);
                bool is_generic = control_type ==  typeof (System.Web.UI.HtmlControls.HtmlGenericControl);
                functions.Push (current_function);
-               if (control_type != typeof (System.Web.UI.WebControls.ListItem))
+               if (control_type != typeof (System.Web.UI.WebControls.ListItem) &&
+                   prev_children_kind != ChildrenKind.DBCOLUMNS) {
                        current_function.AppendFormat ("\t\tprivate System.Web.UI.Control __BuildControl_" +
                                                        "{0} ()\n\t\t{{\n\t\t\t{1} __ctrl;\n\n\t\t\t__ctrl" +
                                                        " = new {1} ({2});\n\t\t\tthis.{0} = __ctrl;\n",
                                                        control_id, control_type,
                                                        (is_generic? "\"" + tag_id + "\"" : ""));
-               else
+               } else {
                        current_function.AppendFormat ("\t\tprivate void __BuildControl_{0} ()\n\t\t{{" +
                                                        "\n\t\t\t{1} __ctrl;\n\t\t\t__ctrl = new {1} ();" +
                                                        "\n\t\t\tthis.{0} = __ctrl;\n",
                                                        control_id, control_type);
+               }
 
                if (children_kind == ChildrenKind.CONTROLS || children_kind == ChildrenKind.OPTION)
                        current_function.Append ("\t\t\tSystem.Web.UI.IParserAccessor __parser = " + 
@@ -930,10 +942,11 @@ class AspGenerator
                string control_type_string = controls.PeekType ().ToString ();
                StringBuilder db_function = controls.DataBindFunction;
                string container;
-               if (controls.Container == null)
+               if (controls.Container == null || !typeof (INamingContainer).IsAssignableFrom (controls.Container))
                        container = "System.Web.UI.Control";
-               else
+               else {
                        container = controls.Container.ToString ();
+               }
 
                if (db_function.Length == 0)
                        db_function.AppendFormat ("\t\tpublic void __DataBind_{0} (object sender, " + 
@@ -1084,8 +1097,20 @@ class AspGenerator
                                                               "FromArgb ({1}, {2}, {3}, {4});\n",
                                                               var_name, c.A, c.R, c.G, c.B);
                        }
-               }       
-               else {
+               }
+               else if (type == typeof (string [])) {
+                       string [] subStrings = att.Split (',');
+                       current_function.AppendFormat ("\t\t\t__ctrl.{0} = new String [] {{\n", var_name);
+                       int end = subStrings.Length;
+                       for (int i = 0; i < end; i++) {
+                               string s = subStrings [i].Trim ();
+                               current_function.AppendFormat ("\t\t\t\t\"{0}\"", s);
+                               if (i == end - 1)
+                                       current_function.Append ("\t\t\t\t};\n");
+                               else
+                                       current_function.Append (",\n");
+                       }
+               } else {
                        throw new ApplicationException ("Unsupported type in property: " + 
                                                        type.ToString ());
                }
@@ -1202,6 +1227,11 @@ class AspGenerator
                }
        }
        
+       private void AddCodeRenderControl (StringBuilder function)
+       {
+               AddCodeRenderControl (function, controls.CodeRenderIndex);
+       }
+
        private void AddCodeRenderControl (StringBuilder function, int index)
        {
                function.AppendFormat ("\t\t\tparameterContainer.Controls [{0}]." + 
@@ -1472,10 +1502,12 @@ class AspGenerator
                NewControlFunction (component.TagID, component.ControlID, component_type,
                                    component.ChildrenKind, component.DefaultPropertyName); 
 
-               if (component_type.IsSubclassOf (typeof (System.Web.UI.UserControl)))
+               if (component_type == typeof (UserControl) ||
+                   component_type.IsSubclassOf (typeof (System.Web.UI.UserControl)))
                        current_function.Append ("\t\t\t__ctrl.InitializeAsUserControl (Page);\n");
 
-               if (component_type.IsSubclassOf (typeof (System.Web.UI.Control)))
+               if (component_type == typeof (Control) ||
+                   component_type.IsSubclassOf (typeof (System.Web.UI.Control)))
                        current_function.AppendFormat ("\t\t\t__ctrl.ID = \"{0}\";\n", component.ControlID);
 
                AddCodeForAttributes (component.ComponentType, component.Attributes);
@@ -1600,7 +1632,7 @@ class AspGenerator
                current_function = new StringBuilder ();
                functions.Push (current_function);
                current_function.AppendFormat ("\t\tprivate void __BuildControl_{0} " +
-                                               "(System.Web.UI.WebControl.DataGridColumnCollection __ctrl)\n" +
+                                               "(System.Web.UI.WebControls.DataGridColumnCollection __ctrl)\n" +
                                                "\t\t{{\n", prop_id);
        }
 
@@ -1783,6 +1815,8 @@ class AspGenerator
                init_funcs.Append (db_function);
                current_function.AppendFormat ("\t\t\tthis.__BuildControl_{0} ();\n\t\t\t__parser." +
                                               "AddParsedSubObject (this.{0});\n\n", control_id);
+
+               AddCodeRenderControl (controls.CodeRenderFunction);
        }
 
        private void ProcessCodeRenderTag ()