Exemple #1
0
 private static void compose(object value, XmlWriter writer)
 {
     if (value == null || value is string)
     {
         writer.WriteMacElementString("string", value as string);
     }
     else if (value is int || value is long)
     {
         writer.WriteMacElementString("integer", ((int)value).ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
     }
     else if (value is IDictionary<string, object>)
     {
         var dic = (IDictionary<string, object>)value;
         writeDictionaryValues(dic, writer);
     }
     else if (value is IList<object>)
     {
         composeArray((IList<object>)value, writer);
     }
     else if (value is byte[])
     {
         writer.WriteMacElementString("data", string.Format("{1}{2}{0}{1}{2}", Convert.ToBase64String((Byte[])value), writer.Settings.NewLineChars, "\t"));
     }
     else if (value is float || value is double)
     {
         writer.WriteMacElementString("real", ((double)value).ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
     }
     else if (value is DateTime)
     {
         DateTime time = (DateTime)value;
         string theString = XmlConvert.ToString(time, XmlDateTimeSerializationMode.Utc);
         writer.WriteMacElementString("date", theString);//, "yyyy-MM-ddTHH:mm:ssZ"));
     }
     else if (value is bool)
     {
         writer.WriteElementString(value.ToString().ToLower(), "");
     }
     else
     {
         throw new Exception(String.Format("Value type '{0}' is unhandled", value.GetType().ToString()));
     }
 }