Esempio n. 1
0
 /// <exception cref="System.IO.IOException"/>
 private void WriteObject(JsonGenerator jg, object value)
 {
     if (value == null)
     {
         jg.WriteNull();
     }
     else
     {
         Type c = value.GetType();
         if (c.IsArray)
         {
             jg.WriteStartArray();
             int len = Runtime.GetArrayLength(value);
             for (int j = 0; j < len; j++)
             {
                 object item = Runtime.GetArrayValue(value, j);
                 WriteObject(jg, item);
             }
             jg.WriteEndArray();
         }
         else
         {
             if (value is Number)
             {
                 Number n = (Number)value;
                 jg.WriteNumber(n.ToString());
             }
             else
             {
                 if (value is bool)
                 {
                     bool b = (bool)value;
                     jg.WriteBoolean(b);
                 }
                 else
                 {
                     if (value is CompositeData)
                     {
                         CompositeData        cds  = (CompositeData)value;
                         CompositeType        comp = cds.GetCompositeType();
                         ICollection <string> keys = comp.KeySet();
                         jg.WriteStartObject();
                         foreach (string key in keys)
                         {
                             WriteAttribute(jg, key, cds.Get(key));
                         }
                         jg.WriteEndObject();
                     }
                     else
                     {
                         if (value is TabularData)
                         {
                             TabularData tds = (TabularData)value;
                             jg.WriteStartArray();
                             foreach (object entry in tds.Values())
                             {
                                 WriteObject(jg, entry);
                             }
                             jg.WriteEndArray();
                         }
                         else
                         {
                             jg.WriteString(value.ToString());
                         }
                     }
                 }
             }
         }
     }
 }