[System.Drawing] Add support for a null culture argument to the ConvertFrom () method...
[mono.git] / mcs / class / System.Drawing / System.Drawing / SizeConverter.cs
index c8bbbbb6c18b490c546dc87430e87969d4d3a2e0..ba8d266cac454af73fc51306aa2103ed28c063c7 100644 (file)
@@ -7,7 +7,7 @@
 //     Ravindra (rkumar@novell.com)
 //
 // Copyright (C) 2002 Ximian, Inc. http://www.ximian.com
-// Copyright (C) 2003,2004,2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2003,2004,2006,2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -68,6 +68,8 @@ namespace System.Drawing {
                                                    CultureInfo culture,
                                                    object value)
                {
+                       if (culture == null)
+                               culture = CultureInfo.CurrentCulture;
                        string s = value as string;
                        if (s == null)
                                return base.ConvertFrom (context, culture, value);
@@ -91,18 +93,21 @@ namespace System.Drawing {
                                                  object value,
                                                  Type destinationType)
                {
+                       if (culture == null)
+                               culture = CultureInfo.CurrentCulture;
                        // LAMESPEC: "The default implementation calls the ToString method
                        // of the object if the object is valid and if the destination
                        // type is string." MS does not behave as per the specs.
                        // Oh well, we have to be compatible with MS.
-                       if ((destinationType == typeof (string)) && (value is Size))
-                               return ((Size) value).Width.ToString(culture) + culture.TextInfo.ListSeparator 
-                                       + " " + ((Size) value).Height.ToString(culture);
-                       
-                       if (destinationType == typeof (InstanceDescriptor) && value is Size) {
-                               Size s = (Size) value;
-                               ConstructorInfo ctor = typeof(Size).GetConstructor (new Type[] {typeof(int), typeof(int)});
-                               return new InstanceDescriptor (ctor, new object[] {s.Width, s.Height});
+                       if (value is Size) {
+                               Size size = (Size) value;
+                               if (destinationType == typeof (string)) {
+                                       return size.Width.ToString (culture) + culture.TextInfo.ListSeparator 
+                                               + " " + size.Height.ToString (culture);
+                               } else if (destinationType == typeof (InstanceDescriptor)) {
+                                       ConstructorInfo ctor = typeof(Size).GetConstructor (new Type[] {typeof(int), typeof(int)});
+                                       return new InstanceDescriptor (ctor, new object[] { size.Width, size.Height });
+                               }
                        }
                        
                        return base.ConvertTo (context, culture, value, destinationType);