Author: ivanz
Date: 2008-02-16 10:10:21 -0500 (Sat, 16 Feb 2008)
New Revision: 95892

Modified:
   
branches/mono-1-9/mcs/class/System.Design/System.ComponentModel.Design/ChangeLog
   
branches/mono-1-9/mcs/class/System.Design/System.ComponentModel.Design/CollectionEditor.cs
Log:
2008-02-16  Ivan N. Zlatev  <[EMAIL PROTECTED]>

        * CollectionEditor.cs: Handle null collection.
        [Part of fix for bugs #360666 and #358332]



Modified: 
branches/mono-1-9/mcs/class/System.Design/System.ComponentModel.Design/ChangeLog
===================================================================
--- 
branches/mono-1-9/mcs/class/System.Design/System.ComponentModel.Design/ChangeLog
    2008-02-16 15:08:41 UTC (rev 95891)
+++ 
branches/mono-1-9/mcs/class/System.Design/System.ComponentModel.Design/ChangeLog
    2008-02-16 15:10:21 UTC (rev 95892)
@@ -1,6 +1,10 @@
+2008-02-16  Ivan N. Zlatev  <[EMAIL PROTECTED]>
+
+       * CollectionEditor.cs: Handle null collection.
+       [Part of fix for bugs #360666 and #358332]
+
 2008-02-12  Ivan N. Zlatev  <[EMAIL PROTECTED]>
 
-       [Backport to 1.9]
        * DateTimeEditor.cs: Set edit value only if the user sets it
        in the editor.
        [Fixes #359159]

Modified: 
branches/mono-1-9/mcs/class/System.Design/System.ComponentModel.Design/CollectionEditor.cs
===================================================================
--- 
branches/mono-1-9/mcs/class/System.Design/System.ComponentModel.Design/CollectionEditor.cs
  2008-02-16 15:08:41 UTC (rev 95891)
+++ 
branches/mono-1-9/mcs/class/System.Design/System.ComponentModel.Design/CollectionEditor.cs
  2008-02-16 15:10:21 UTC (rev 95892)
@@ -84,9 +84,23 @@
                        {
                                get { return editor.GetItems (editValue); }
                                set {
-                                       object val = editor.SetItems 
(editValue, value);
-                                       if (val != EditValue)
-                                               EditValue = val;
+                                       if (editValue == null) {
+                                               object newEmptyCollection = 
null;
+                                               try {
+                                                       if (typeof 
(Array).IsAssignableFrom (CollectionType))
+                                                               
newEmptyCollection = Array.CreateInstance (CollectionItemType, 0);
+                                                       else
+                                                               
newEmptyCollection = Activator.CreateInstance (CollectionType);
+                                               } catch {}
+
+                                               object val = editor.SetItems 
(newEmptyCollection, value);
+                                               if (val != newEmptyCollection)
+                                                       EditValue = val;
+                                       } else {
+                                               object val = editor.SetItems 
(editValue, value);
+                                               if (val != editValue)
+                                                       EditValue = val;
+                                       }
                                }
                        }
 
@@ -618,9 +632,7 @@
                                {
                                        CollectionForm editorForm = 
CreateCollectionForm ();
                                        editorForm.EditValue = value;
-
                                        editorForm.ShowEditorDialog 
(editorService);
-
                                        return editorForm.EditValue;
                                }
                        }
@@ -655,7 +667,7 @@
                protected virtual object[] GetItems (object editValue)
                {
                        if (editValue == null)
-                               return null;
+                               return new object[0];
                        ICollection collection = editValue as ICollection;
                        if (collection == null)
                                return new object[0];
@@ -679,19 +691,11 @@
 
                protected virtual object SetItems (object editValue, object[] 
value)
                {
-                       IList list;
-
-                       if (editValue == null)
+                       IList list = (IList) editValue;
+                       if (list == null)
                                return null;
 
-                       if (!(editValue is IList))
-                               list = new ArrayList ();
-                       else
-                       {
-                               list = editValue as IList;
-                               list.Clear ();
-                       }
-
+                       list.Clear ();
                        foreach (object o in value)
                                list.Add (o);
 

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

Reply via email to