2004-03-10 Joerg Rosenkranz <JoergR@voelcker.com>
authorMiguel de Icaza <miguel@gnome.org>
Wed, 10 Mar 2004 14:47:34 +0000 (14:47 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 10 Mar 2004 14:47:34 +0000 (14:47 -0000)
* BooleanType.cs:
Corrected implementation of method FromString.
This fixes bug #55414.

svn path=/trunk/mcs/; revision=23879

mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/BooleanType.cs
mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/ChangeLog

index 45183bd6c333ae4777f7695c9b87b7c894dcb98a..b897cc8772f0a7dcaa22239fa7c826803173b48d 100644 (file)
@@ -4,12 +4,15 @@
 // Author:
 //   Chris J Breisch (cjbreisch@altavista.net) 
 //   Francesco Delfino (pluto@tipic.com)
+//   Joerg Rosenkranz (JoergR@voelcker.com)
 //
 // (C) 2002 Chris J Breisch
 //     2002 Tipic, Inc (http://www.tipic.com)
+//     2004 Joerg Rosenkranz
 //
 
 using System;
+using System.Globalization;
 
 namespace Microsoft.VisualBasic.CompilerServices 
 {
@@ -20,12 +23,31 @@ namespace Microsoft.VisualBasic.CompilerServices
                // Constructors
                // Properties
                // Methods
-               public static System.Boolean FromString (System.String Value) { return System.Boolean.Parse(Value); }
+               public static System.Boolean FromString (System.String Value) 
+               {
+                       if (string.Compare(Value, bool.TrueString, true) == 0)
+                               return true;
+                       
+                       if (string.Compare(Value, bool.FalseString, true) == 0)
+                               return false;
+                       
+                       double conv;
+                       if (double.TryParse(Value, NumberStyles.Any, NumberFormatInfo.InvariantInfo, out conv))
+                               return (conv != 0);
+                       
+                       throw new InvalidCastException (
+                               string.Format (
+                                       "Cast from string \"{0}\" to type 'Boolean' is not valid.",
+                                       Value));
+               }
+               
                public static System.Boolean FromObject (System.Object Value) 
                {
                        if ((object)Value == null) return false;
-                       //if (Value.GetType() == typeof(string)) return FromString((string)Value);
-                       else return System.Convert.ToBoolean(Value);
+                       if (Value is string) 
+                               return FromString((string)Value);
+                       else 
+                               return System.Convert.ToBoolean(Value);
                }
                // Events
        };
index b5966984c917f7c925ec4ff1980d9f16243ca2f6..62172beca762350e572793be16748b3956509b64 100644 (file)
@@ -1,3 +1,8 @@
+2004-03-10     Joerg Rosenkranz <JoergR@voelcker.com>
+       * BooleanType.cs:
+               Corrected implementation of method FromString. 
+               This fixes bug #55414.
+
 2004-02-20  Rafael Teixeira <rafaelteixeirabr@hotmail.com>
        * OptionCompareAttribute.cs:\r
                Corrected constructor of attribute (bug #52570)