Author: gonzalo
Date: 2005-05-10 17:21:53 -0400 (Tue, 10 May 2005)
New Revision: 44355

Modified:
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs
Log:
2005-05-10 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * DataGrid.cs: cleanup in AutoCreateColumns. Don't throw at the end of
        the method if the data source was en empty IEnumerator. Fixes
        bug #74804.



Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2005-05-10 21:12:23 UTC (rev 44354)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2005-05-10 21:21:53 UTC (rev 44355)
@@ -1,3 +1,9 @@
+2005-05-10 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * DataGrid.cs: cleanup in AutoCreateColumns. Don't throw at the end of
+       the method if the data source was en empty IEnumerator. Fixes
+       bug #74804.
+
 2005-05-06  Lluis Sanchez Gual <[EMAIL PROTECTED]>
 
        * TreeNode.cs:

Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs    
2005-05-10 21:12:23 UTC (rev 44354)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs    
2005-05-10 21:21:53 UTC (rev 44355)
@@ -1501,92 +1501,90 @@
                /// This method is called by CreateColumnSet when dataSource
                /// is to be used and columns need to be generated 
automatically.
                /// </summary>
-               private ArrayList AutoCreateColumns(PagedDataSource source)
+               private ArrayList AutoCreateColumns (PagedDataSource source)
                {
-                       if(source != null)
-                       {
-                               ArrayList retVal = new ArrayList();
-                               PropertyDescriptorCollection props = 
source.GetItemProperties(new PropertyDescriptor[0]);
-                               Type      prop_type;
-                               BoundColumn b_col;
-                               if(props == null)
-                               {
-                                       object fitem = null;
-                                       prop_type   = null;
-                                       PropertyInfo prop_item =  
source.DataSource.GetType().GetProperty("Item",
-                                                 BindingFlags.Instance | 
BindingFlags.Static |
-                                                 BindingFlags.Public, null, 
null,
-                                                 new Type[] { typeof(int) }, 
null);
-                                       
-                                       if(prop_item != null)
-                                       {
-                                               prop_type = 
prop_item.PropertyType;
+                       if (source == null)
+                               return null;
+
+                       ArrayList retVal = null;
+                       PropertyDescriptorCollection props = 
source.GetItemProperties (new PropertyDescriptor [0]);
+                       bool empty_enumerator = false;
+                       Type prop_type;
+                       BoundColumn col;
+
+                       if (props == null) {
+                               object fitem = null;
+                               prop_type   = null;
+                               PropertyInfo prop_item =  
source.DataSource.GetType ().GetProperty ("Item",
+                                         BindingFlags.Instance | 
BindingFlags.Static | BindingFlags.Public,
+                                         null, null, new Type[] { typeof(int) 
}, null);
+                               
+                               if (prop_item != null)
+                                       prop_type = prop_item.PropertyType;
+
+                               if (prop_type == null || prop_type == typeof 
(object)) {
+                                       IEnumerator en = source.GetEnumerator();
+                                       if (en.MoveNext ()) {
+                                               fitem = en.Current;
+                                               if (fitem != null)
+                                                       prop_type = 
fitem.GetType ();
+                                       } else {
+                                               empty_enumerator = true;
                                        }
-                                       if(prop_type == null || prop_type == 
typeof(object))
-                                       {
-                                               
-                                               IEnumerator en = 
source.GetEnumerator();
-                                               if(en.MoveNext())
-                                                       fitem = en.Current;
-                                               if(fitem != null)
-                                               {
-                                                       prop_type = 
fitem.GetType();
-                                               }
-                                               StoreEnumerator(en, fitem);
+
+                                       StoreEnumerator (en, fitem);
+                               }
+                               
+                               if (fitem is ICustomTypeDescriptor) {
+                                       props = TypeDescriptor.GetProperties 
(fitem);
+                               } else if (prop_type != null) {
+                                       if (IsBindableType  (prop_type)) {
+                                               col = new BoundColumn ();
+                                               ((IStateManager) 
col).TrackViewState ();
+                                               col.HeaderText = "Item";
+                                               col.SortExpression = "Item";
+                                               col.DataField  = 
BoundColumn.thisExpr;
+                                               col.SetOwner (this);
+                                               if (retVal == null)
+                                                       retVal = new ArrayList 
();
+                                               retVal.Add (col);
+                                       } else {
+                                               props = 
TypeDescriptor.GetProperties (prop_type);
                                        }
-                                       
-                                       if(fitem != null && fitem is 
ICustomTypeDescriptor)
-                                       {
-                                               props = 
TypeDescriptor.GetProperties(fitem);
-                                       } else if(prop_type != null) {
-                                               if(IsBindableType(prop_type))
-                                               {
-                                                       b_col = new 
BoundColumn();
-                                                       
((IStateManager)b_col).TrackViewState();
-                                                       b_col.HeaderText = 
"Item";
-                                                       b_col.SortExpression = 
"Item";
-                                                       b_col.DataField  = 
BoundColumn.thisExpr;
-                                                       b_col.SetOwner(this);
-                                                       retVal.Add(b_col);
-                                               } else
-                                               {
-                                                       props = 
TypeDescriptor.GetProperties(prop_type);
-                                               }
-                                       }
-                                       
                                }
-                               if(props != null && props.Count > 0)
-                               {
-                                       //IEnumerable p_en = 
props.GetEnumerator();
-                                       try
-                                       {
-                                               foreach(PropertyDescriptor 
current in props)
-                                               {
-                                                       
if(IsBindableType(current.PropertyType))
-                                                       {
-                                                               b_col = new 
BoundColumn();
-                                                               
((IStateManager)b_col).TrackViewState();
-                                                               
b_col.HeaderText     = current.Name;
-                                                               
b_col.SortExpression = current.Name;
-                                                               b_col.DataField 
     = current.Name;
-                                                               b_col.ReadOnly  
   = current.IsReadOnly;
-                                                               
b_col.SetOwner(this);
-                                                               
retVal.Add(b_col);
-                                                       }
-                                               }
-                                       } finally
-                                       {
-                                               if(props is IDisposable)
-                                                       
((IDisposable)props).Dispose();
+                       }
+
+                       if (props != null && props.Count > 0) {
+                               try {
+                                       foreach (PropertyDescriptor current in 
props) {
+                                               if (!IsBindableType 
(current.PropertyType))
+                                                       continue;
+
+                                               col = new BoundColumn ();
+                                               ((IStateManager) 
col).TrackViewState ();
+                                               string name = current.Name;
+                                               col.HeaderText = name;
+                                               col.SortExpression = name;
+                                               col.DataField = name;
+                                               col.ReadOnly = 
current.IsReadOnly;
+                                               col.SetOwner (this);
+                                               if (retVal == null)
+                                                       retVal = new ArrayList 
();
+                                               retVal.Add (col);
                                        }
+                               } finally {
+                                       if (props is IDisposable)
+                                               ((IDisposable) props).Dispose 
();
                                }
-                               if(retVal.Count > 0)
-                               {
-                                       return retVal;
-                               }
-                               throw new 
HttpException(HttpRuntime.FormatResourceString("DataGrid_NoAutoGenColumns", 
ID));
                        }
-                       return null;
+
+                       if (retVal != null && retVal.Count > 0)
+                               return retVal;
+
+                       if (empty_enumerator)
+                               return null;
+
+                       throw new HttpException 
(HttpRuntime.FormatResourceString ("DataGrid_NoAutoGenColumns", ID));
                }
 
                internal void StoreEnumerator(IEnumerator source, object 
firstItem)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to