* ExpressionCollection.cs (ConvertToObject): Allow true/on/yes
authorAnkit Jain <radical@corewars.org>
Mon, 27 Apr 2009 11:41:06 +0000 (11:41 -0000)
committerAnkit Jain <radical@corewars.org>
Mon, 27 Apr 2009 11:41:06 +0000 (11:41 -0000)
as valid true values for bool, and corresponding for false.

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

mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ExpressionCollection.cs

index 2fbef1e58c114bb290151e8847d62f0333788896..2caad67aba121ae7b233ab9e0f2781d2bf866f6c 100644 (file)
@@ -1,3 +1,8 @@
+2009-04-27  Ankit Jain  <jankit@novell.com>
+
+       * ExpressionCollection.cs (ConvertToObject): Allow true/on/yes
+       as valid true values for bool, and corresponding for false.
+
 2009-03-27  Jonathan Chambers  <joncham@gmail.com>
 
        * BuildWhen.cs: Add basic implementation.
index 8e262c81475f4cfa5489a00e64225edcbe5c9c5e..957e0fcb2d23a1ab5377d64329e1ee587ed961d2 100644 (file)
@@ -41,6 +41,19 @@ namespace Microsoft.Build.BuildEngine {
        internal class ExpressionCollection {
        
                IList objects;
+               static Dictionary<string, bool> boolValues;
+
+               static ExpressionCollection ()
+               {
+                       string[] trueValuesArray = new string[] {"true", "on", "yes"};
+                       string[] falseValuesArray = new string[] {"false", "off", "no"};
+
+                       boolValues = new Dictionary<string, bool> (StringComparer.InvariantCultureIgnoreCase);
+                       foreach (string s in trueValuesArray)
+                               boolValues.Add (s, true);
+                       foreach (string s in falseValuesArray)
+                               boolValues.Add (s, false);
+               }
        
                public ExpressionCollection ()
                {
@@ -100,9 +113,15 @@ namespace Microsoft.Build.BuildEngine {
 
                object ConvertToObject (string raw, Type type)
                {
-                       if (type == typeof (bool))
-                               return Boolean.Parse (raw);
-                       else if (type == typeof (string))
+                       if (type == typeof (bool)) {
+                               bool value;
+                               if (boolValues.TryGetValue (raw, out value))
+                                       return value;
+                               else
+                                       return false;
+                       }
+
+                       if (type == typeof (string))
                                return raw;
                        else if (type == typeof (int))
                                return Int32.Parse (raw);