/// <summary>
 /// Gets the underlying value of the Value object.
 /// </summary>
 /// <value>The Value object to get the value from.</value>
 /// <returns>The underlying value.</returns>
 public static object GetValue(Value value) {
   PropertyInfo propInfo = value.GetType().GetProperty("value");
   if (propInfo != null) {
     return propInfo.GetValue(value, null);
   }
   return null;
 }
    private static bool ValuesAreEqual(Value value1, Value value2) {
       Dictionary<Type, ValueEqualityDelegate> switcher = 
         new Dictionary<Type, ValueEqualityDelegate>();
      switcher.Add(typeof(TextValue), new ValueEqualityDelegate(TextValuesAreEqual));
      switcher.Add(typeof(NumberValue), new ValueEqualityDelegate(NumberValuesAreEqual));
      switcher.Add(typeof(BooleanValue), new ValueEqualityDelegate(BooleanValuesAreEqual));
      switcher.Add(typeof(SetValue), new ValueEqualityDelegate(SetValuesAreEqual));
      switcher.Add(typeof(DateValue), new ValueEqualityDelegate(DateValuesAreEqual));
      switcher.Add(typeof(DateTimeValue), new ValueEqualityDelegate(DateTimeValuesAreEqual));

      if (switcher.ContainsKey(value1.GetType())) {
        return switcher[value1.GetType()](value1, value2);
      }
      throw new NotImplementedException(String.Format("Unknown Value type {0}", value1.GetType()));
    }
 /// <summary>
 /// Adds a new value to the list of query parameters.
 /// </summary>
 /// <param name="key">The parameter name.</param>
 /// <param name="value">The parameter value.</param>
 /// <returns>The statement builder, for chaining method calls.</returns>
 private StatementBuilder AddValue(string key, Value value) {
   String_ValueMapEntry queryValue = new String_ValueMapEntry();
   queryValue.key = key;
   queryValue.value = value;
   valueEntries.Add(queryValue);
   return this;
 }
    private static bool SetValuesAreEqual(Value value1, Value value2) {
      Value[] set1 = (value1 as SetValue).values;
      Value[] set2 = (value2 as SetValue).values;

      if (set1.Length != set2.Length) {
        return false;
      }

      for (int i = 0; i < set1.Length; i++) {
        if (!ValuesAreEqual(set1[i], set2[i])) {
          return false;
        }
      }
      return true;
    }
 private static bool BooleanValuesAreEqual(Value value1, Value value2) {
   return (value1 as BooleanValue).value == (value2 as BooleanValue).value;
 }
 private static bool NumberValuesAreEqual(Value value1, Value value2) {
   return String.Equals((value1 as NumberValue).value, (value2 as NumberValue).value);
 }
 private static bool DateTimeValuesAreEqual(Value value1, Value value2) {
   DateTime dateTime1 = (value1 as DateTimeValue).value;
   DateTime dateTime2 = (value2 as DateTimeValue).value;
   return DatesAreEqual(dateTime1.date, dateTime2.date)
       && dateTime1.hour == dateTime2.hour
       && dateTime1.minute == dateTime2.minute
       && dateTime1.second == dateTime2.second
       && String.Equals(dateTime1.timeZoneID, dateTime2.timeZoneID);
 }
 private static bool DateValuesAreEqual(Value value1, Value value2) {
   Date date1 = (value1 as DateValue).value;
   Date date2 = (value2 as DateValue).value;
   return DatesAreEqual(date1, date2);
 }