[Mono-bugs] [Bug 57460][Nor] New - System.ComponentModel BooleanConverter string conversion

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 22 Apr 2004 17:41:17 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by davide@devage.com.

http://bugzilla.ximian.com/show_bug.cgi?id=57460

--- shadow/57460	2004-04-22 17:41:17.000000000 -0400
+++ shadow/57460.tmp.16215	2004-04-22 17:41:17.000000000 -0400
@@ -0,0 +1,60 @@
+Bug#: 57460
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: davide@devage.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: System.ComponentModel BooleanConverter string conversion
+
+Description of Problem:
+I think that the method ConvertFrom of the class
+System.ComponentModel.BooleanConverter is not correct. First because the
+CultureInfo is an optional parameter and can be null and in this case the
+ToLower method throw an exception. Second because I think is better to use
+the bool.Parse method.
+This is the old code:
+		public override object ConvertFrom (ITypeDescriptorContext context,
+CultureInfo culture, object value)
+		{
+			if (value.GetType() == typeof (string)) {
+				string Test = ((String) value).ToLower (culture);
+				if (Test.Equals ("true"))
+					return true;
+				else if (Test.Equals ("false"))
+					return false;
+				else
+					throw new FormatException ("No valid boolean value");
+			}
+
+			return base.ConvertFrom (context, culture, value);
+		}
+
+and this is the code that I would write:
+
+		public override object ConvertFrom (ITypeDescriptorContext context,
+CultureInfo culture, object value)
+		{
+			if (value is string)
+			{
+				string Test = ((string)value).Trim();
+				
+				return bool.Parse(Test);
+			}
+
+			return base.ConvertFrom (context, culture, value);
+		}
+
+Hope this helps
+
+
+Davide Icardi