+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.
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 ()
{
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);