Hi,

The attached patch fixes some NullReferenceExceptions in PropertyGrid,
and fixes some NotWorking unit tests.

Let me know if it's ok to commit.

Gert
Index: Test/System.Windows.Forms/ChangeLog
===================================================================
--- Test/System.Windows.Forms/ChangeLog	(revision 66654)
+++ Test/System.Windows.Forms/ChangeLog	(working copy)
@@ -1,5 +1,9 @@
 2006-10-13  Gert Driesen  <[EMAIL PROTECTED]>
 
+	* PropertyGridTest.cs: Enabled previously not-working tests.
+
+2006-10-13  Gert Driesen  <[EMAIL PROTECTED]>
+
 	* PropertyGridTest.cs: Added some tests for PropertyGrid.
 
 2006-10-13  Andreia Gaita  <[EMAIL PROTECTED]>
Index: Test/System.Windows.Forms/PropertyGridTest.cs
===================================================================
--- Test/System.Windows.Forms/PropertyGridTest.cs	(revision 66654)
+++ Test/System.Windows.Forms/PropertyGridTest.cs	(working copy)
@@ -18,7 +18,6 @@
 	public class PropertyGridTest
 	{
 		[Test]
-		[Category ("NotWorking")]
 		public void SelectedObject ()
 		{
 			PropertyGrid pg = new PropertyGrid ();
@@ -35,7 +34,6 @@
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		public void SelectedObject_Null ()
 		{
 			PropertyGrid pg = new PropertyGrid ();
@@ -49,7 +47,6 @@
 		}
 
 		[Test] // bug #79615
-		[Category ("NotWorking")]
 		public void SelectedObjects_Multiple ()
 		{
 			Form form = new Form ();
@@ -70,7 +67,6 @@
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		public void SelectedObjects_Null ()
 		{
 			PropertyGrid pg = new PropertyGrid ();

Property changes on: Test/System.Windows.Forms/PropertyGridTest.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Index: System.Windows.Forms/ChangeLog
===================================================================
--- System.Windows.Forms/ChangeLog	(revision 66653)
+++ System.Windows.Forms/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2006-10-13  Gert Driesen  <[EMAIL PROTECTED]>
+
+	* PropertyGrid.cs: Fixed some NRE's and small difference between our
+	implementation and that of MS.
+
 2006-10-13  Chris Toshok  <[EMAIL PROTECTED]>
 
 	* Control.cs (OnInvalidated) only futz with the invalid_region if
Index: System.Windows.Forms/PropertyGrid.cs
===================================================================
--- System.Windows.Forms/PropertyGrid.cs	(revision 66653)
+++ System.Windows.Forms/PropertyGrid.cs	(working copy)
@@ -82,7 +82,7 @@
 		
 		#region Contructors
 		public PropertyGrid() {
-			selected_objects = new object[1];
+			selected_objects = new object[0];
 			grid_items = new GridItemCollection();
 			property_tabs = new PropertyTabCollection();
 
@@ -489,7 +489,9 @@
 		[TypeConverter("System.Windows.Forms.PropertyGrid+SelectedObjectConverter, " + Consts.AssemblySystem_Windows_Forms)]
 		public object SelectedObject {
 			get {
-				return selected_objects[0];
+				if (selected_objects.Length > 0)
+					return selected_objects[0];
+				return null;
 			}
 
 			set {
@@ -521,11 +523,15 @@
 			}
 
 			set {
-				for (int i = 0; i < value.Length; i ++) {
-					if (value[i] == null)
-						throw new ArgumentException (String.Format ("Item {0} in the objs array is null.", i));
+				if (value != null) {
+					for (int i = 0; i < value.Length; i++) {
+						if (value [i] == null)
+							throw new ArgumentException (String.Format ("Item {0} in the objs array is null.", i));
+					}
+					selected_objects = value;
+				} else {
+					selected_objects = new object [0];
 				}
-				selected_objects = value;
 				ReflectObjects();
 			}
 		}
@@ -1004,7 +1010,7 @@
 				intersection = new_intersection;
 			}
 
-			if (intersection.Count > 0)
+			if (intersection != null && intersection.Count > 0)
 				PopulateGridItemsFromProperties (objs, intersection, grid_item_coll, recurse, parent_grid_item);
 		}
 
@@ -1032,10 +1038,13 @@
 				}
 
 				if (recurse && TypeDescriptor.GetConverter(property.PropertyType).GetPropertiesSupported()) {
-					object[] subobjs = new object[objs.Length];
-					for (int i = 0; i < objs.Length; i ++)
-						subobjs[i] = property.GetValue (objs[i]);
-					PopulateMergedGridItems (subobjs, grid_entry.GridItems, false, grid_entry);
+					ArrayList subobjs = new ArrayList (objs.Length);
+					for (int i = 0; i < objs.Length; i++) {
+						object val = property.GetValue (objs [i]);
+						if (val != null)
+							subobjs.Add (val);
+					}
+					PopulateMergedGridItems (subobjs.ToArray(), grid_entry.GridItems, false, grid_entry);
 				}
 				grid_entry.Expanded = false;
 			}
_______________________________________________
Mono-winforms-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

Reply via email to