Changed System.Windows.Forms.ToolStripManager.RevertMerge to return
authorChad Dettmering <chad.dettmering@gmail.com>
Thu, 26 Feb 2015 22:31:49 +0000 (17:31 -0500)
committerChad Dettmering <chad.dettmering@gmail.com>
Thu, 26 Feb 2015 22:31:49 +0000 (17:31 -0500)
false when given a null argument instead of throwing an exception.
According to the msdn here:
https://msdn.microsoft.com/en-us/library/b4e35dwy%28v=vs.110%29.aspx
this method should never throw an exception. This was also confirmed
with the official Microsoft runtime.

This change is released under the MIT license.

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripManager.cs
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ToolStripManagerTest.cs

index d85ae420f05b30d196a0cd8c212e03b4adfe5508..760ace67be3895a5009b6b0b490806abb86e09cc 100644 (file)
@@ -354,13 +354,16 @@ namespace System.Windows.Forms
                
                public static bool RevertMerge (ToolStrip targetToolStrip)
                {
+            if (targetToolStrip == null)
+                return false;
+
                        return RevertMerge (targetToolStrip, targetToolStrip.CurrentlyMergedWith);                      
                }
                
                public static bool RevertMerge (ToolStrip targetToolStrip, ToolStrip sourceToolStrip)
                {
                        if (sourceToolStrip == null)
-                               throw new ArgumentNullException ("sourceToolStrip");
+                return false;
                                
                        List<ToolStripItem> items_to_move = new List<ToolStripItem> ();
                        
index c9a11bc9bea36a95f4848788a01aa614faf7b41e..626930d497ba8fdfd66e4486d3ccfa1ef5aa2417 100644 (file)
@@ -578,12 +578,27 @@ namespace MonoTests.System.Windows.Forms
                }\r
 \r
                [Test]\r
-               [ExpectedException (typeof (ArgumentNullException))]\r
-               public void MethodRevertMergeANE ()\r
+               public void MethodRevertMergeNullArgument1 ()\r
+               {\r
+            String ts = null;\r
+\r
+                       Assert.AreEqual (false, ToolStripManager.RevertMerge (ts), "C1");\r
+               }\r
+\r
+               [Test]\r
+               public void MethodRevertMergeNullArgument2 ()\r
+               {\r
+                       ToolStrip ts = null;\r
+\r
+                       Assert.AreEqual (false, ToolStripManager.RevertMerge (ts), "C2");\r
+               }\r
+\r
+               [Test]\r
+               public void MethodRevertMergeNullArgument3 ()\r
                {\r
                        ToolStrip ts = new ToolStrip ();\r
                        \r
-                       ToolStripManager.RevertMerge (ts, null);\r
+                       Assert.AreEqual (false, ToolStripManager.RevertMerge (ts, null), "C3");\r
                }\r
                \r
                [Test]\r