Exemplo n.º 1
0
        private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
        {
            if (obj == null)
            {
                writer.Write(null);
                return;
            }

            if (obj.IsString)
            {
                writer.Write(obj.GetString());
                return;
            }

            if (obj.IsBoolean)
            {
                writer.Write(obj.GetBoolean());
                return;
            }

            if (obj.IsDouble)
            {
                writer.Write(obj.GetDouble());
                return;
            }

            if (obj.IsInt)
            {
                writer.Write(obj.GetInt());
                return;
            }

            if (obj.IsLong)
            {
                writer.Write(obj.GetLong());
                return;
            }

            if (obj.IsArray)
            {
                writer.WriteArrayStart();
                foreach (object elem in (IList)obj)
                {
                    WriteJson((JsonData)elem, writer);
                }
                writer.WriteArrayEnd();

                return;
            }

            if (obj.IsObject)
            {
                writer.WriteObjectStart();

                foreach (DictionaryEntry entry in (IDictionary)obj)
                {
                    writer.WritePropertyName((string)entry.Key);
                    WriteJson((JsonData)entry.Value, writer);
                }
                writer.WriteObjectEnd();
            }
        }
        private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
        {
            if (obj.IsString) {
                writer.Write (obj.GetString ());
                return;
            }

            if (obj.IsBoolean) {
                writer.Write (obj.GetBoolean ());
                return;
            }

            if (obj.IsDouble) {
                writer.Write (obj.GetDouble ());
                return;
            }

            if (obj.IsInt) {
                writer.Write (obj.GetInt ());
                return;
            }

            if (obj.IsLong) {
                writer.Write (obj.GetLong ());
                return;
            }

            if (obj.IsArray) {
                writer.WriteArrayStart ();
                foreach (object elem in (IList) obj)
                    WriteJson ((JsonData) elem, writer);
                writer.WriteArrayEnd ();

                return;
            }

            if (obj.IsObject) {
                writer.WriteObjectStart ();

                foreach (DictionaryEntry entry in ((IDictionary) obj)) {
                    writer.WritePropertyName ((string) entry.Key);
                    WriteJson ((JsonData) entry.Value, writer);
                }
                writer.WriteObjectEnd ();

                return;
            }
        }
Exemplo n.º 3
0
        private static void WriteJson(IJsonWrapper wrapper, JsonWriter writer)
        {
            if (wrapper == null)
            {
                writer.Write(null);
                return;
            }

            if (wrapper.IsString)
            {
                writer.Write(wrapper.GetString());
                return;
            }

            if (wrapper.IsBoolean)
            {
                writer.Write(wrapper.GetBoolean());
                return;
            }

            if (wrapper.IsDouble)
            {
                writer.Write(wrapper.GetDouble());
                return;
            }

            if (wrapper.IsInt)
            {
                writer.Write(wrapper.GetInt());
                return;
            }

            if (wrapper.IsLong)
            {
                writer.Write(wrapper.GetLong());
                return;
            }

            if (wrapper.IsArray)
            {
                writer.WriteArrayStart();
                foreach (object elem in (IList)wrapper)
                {
                    WriteJson((JsonData)elem, writer);
                }
                writer.WriteArrayEnd();
                return;
            }

            if (wrapper.IsObject)
            {
                if (((IDictionary)wrapper).Count <= 0)
                {
                    return;
                }

                writer.WriteObjectStart();

                foreach (DictionaryEntry entry in ((IDictionary)wrapper))
                {
                    //TODO: ignore null entry
                    var data = (JsonData)entry.Value;
                    var type = data.GetJsonType();
                    if (type == JsonType.None)
                    {
                        continue;
                    }
                    if (type == JsonType.Array && ((IList)entry.Value).Count <= 0)
                    {
                        continue;
                    }
                    writer.WritePropertyName((string)entry.Key);
                    WriteJson(data, writer);
                }
                writer.WriteObjectEnd();

                return;
            }

            if (wrapper.GetJsonType() == JsonType.None)
            {
                writer.WriteObjectStart();
                writer.WriteObjectEnd();
                return;
            }
        }
Exemplo n.º 4
0
 private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
 {
     if (obj.IsString)
     {
         writer.Write(obj.GetString());
         return;
     }
     if (obj.IsBoolean)
     {
         writer.Write(obj.GetBoolean());
         return;
     }
     if (obj.IsDouble)
     {
         writer.Write(obj.GetDouble());
         return;
     }
     if (obj.IsInt)
     {
         writer.Write(obj.GetInt());
         return;
     }
     if (obj.IsLong)
     {
         writer.Write(obj.GetLong());
         return;
     }
     if (obj.IsArray)
     {
         writer.WriteArrayStart();
         IEnumerator enumerator = obj.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 object obj2 = enumerator.Current;
                 JsonData.WriteJson((JsonData)obj2, writer);
             }
         }
         finally
         {
             IDisposable disposable;
             if ((disposable = (enumerator as IDisposable)) != null)
             {
                 disposable.Dispose();
             }
         }
         writer.WriteArrayEnd();
         return;
     }
     if (obj.IsObject)
     {
         writer.WriteObjectStart();
         IDictionaryEnumerator enumerator2 = obj.GetEnumerator();
         try
         {
             while (enumerator2.MoveNext())
             {
                 object          obj3            = enumerator2.Current;
                 DictionaryEntry dictionaryEntry = (DictionaryEntry)obj3;
                 writer.WritePropertyName((string)dictionaryEntry.Key);
                 JsonData.WriteJson((JsonData)dictionaryEntry.Value, writer);
             }
         }
         finally
         {
             IDisposable disposable2;
             if ((disposable2 = (enumerator2 as IDisposable)) != null)
             {
                 disposable2.Dispose();
             }
         }
         writer.WriteObjectEnd();
         return;
     }
 }
Exemplo n.º 5
0
 private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
 {
     if (obj == null)
     {
         writer.Write((string)null);
     }
     else if (obj.IsString)
     {
         writer.Write(obj.GetString());
     }
     else if (obj.IsBoolean)
     {
         writer.Write(obj.GetBoolean());
     }
     else if (obj.IsDouble)
     {
         writer.Write(obj.GetDouble());
     }
     else if (obj.IsInt)
     {
         writer.Write(obj.GetInt());
     }
     else if (obj.IsLong)
     {
         writer.Write(obj.GetLong());
     }
     else if (obj.IsArray)
     {
         writer.WriteArrayStart();
         IEnumerator enumerator = obj.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 object current = enumerator.Current;
                 WriteJson((JsonData)current, writer);
             }
         }
         finally
         {
             IDisposable disposable = enumerator as IDisposable;
             if (disposable == null)
             {
             }
             disposable.Dispose();
         }
         writer.WriteArrayEnd();
     }
     else if (obj.IsObject)
     {
         writer.WriteObjectStart();
         IDictionaryEnumerator enumerator2 = obj.GetEnumerator();
         try
         {
             while (enumerator2.MoveNext())
             {
                 DictionaryEntry entry = (DictionaryEntry)enumerator2.Current;
                 writer.WritePropertyName((string)entry.Key);
                 WriteJson((JsonData)entry.Value, writer);
             }
         }
         finally
         {
             IDisposable disposable2 = enumerator2 as IDisposable;
             if (disposable2 == null)
             {
             }
             disposable2.Dispose();
         }
         writer.WriteObjectEnd();
     }
 }
Exemplo n.º 6
0
 private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
 {
     if (obj == null)
     {
         writer.Write(null);
     }
     else if (obj.IsString)
     {
         writer.Write(obj.GetString());
     }
     else if (obj.IsBoolean)
     {
         writer.Write(obj.GetBoolean());
     }
     else if (obj.IsDouble)
     {
         writer.Write(obj.GetDouble());
     }
     else if (obj.IsInt)
     {
         writer.Write(obj.GetInt());
     }
     else if (obj.IsUInt)
     {
         writer.Write(obj.GetUInt());
     }
     else if (obj.IsLong)
     {
         writer.Write(obj.GetLong());
     }
     else if (obj.IsULong)
     {
         writer.Write(obj.GetULong());
     }
     else if (obj.IsArray)
     {
         writer.WriteArrayStart();
         foreach (JsonData item in (IEnumerable)obj)
         {
             WriteJson(item, writer);
         }
         writer.WriteArrayEnd();
     }
     else if (obj.IsObject)
     {
         writer.WriteObjectStart();
         IDictionaryEnumerator enumerator2 = ((IDictionary)obj).GetEnumerator();
         try
         {
             while (enumerator2.MoveNext())
             {
                 DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator2.Current;
                 writer.WritePropertyName((string)dictionaryEntry.Key);
                 WriteJson((JsonData)dictionaryEntry.Value, writer);
             }
         }
         finally
         {
             (enumerator2 as IDisposable)?.Dispose();
         }
         writer.WriteObjectEnd();
     }
 }
Exemplo n.º 7
0
        private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
        {
            if (obj.IsString)
            {
                writer.Write(obj.GetString());
                return;
            }

            if (obj.IsBoolean)
            {
                writer.Write(obj.GetBoolean());
                return;
            }

            if (obj.IsDouble)
            {
                writer.Write(obj.GetDouble());
                return;
            }

            if (obj.IsInt)
            {
                writer.Write(obj.GetInt());
                return;
            }

            if (obj.IsLong)
            {
                writer.Write(obj.GetLong());
                return;
            }

            if (obj.IsArray)
            {
                writer.WriteArrayStart();
                {
                    // foreach(var elem in (IList) obj)
                    var __enumerator3 = ((IList)obj).GetEnumerator();
                    while (__enumerator3.MoveNext())
                    {
                        var elem = (object)__enumerator3.Current;
                        WriteJson((JsonData)elem, writer);
                    }
                }
                writer.WriteArrayEnd();

                return;
            }

            if (obj.IsObject)
            {
                writer.WriteObjectStart();
                {
                    // foreach(var entry in ((IDictionary) obj))
                    var __enumerator4 = (((IDictionary)obj)).GetEnumerator();
                    while (__enumerator4.MoveNext())
                    {
                        var entry = (DictionaryEntry)__enumerator4.Current;
                        {
                            writer.WritePropertyName((string)entry.Key);
                            WriteJson((JsonData)entry.Value, writer);
                        }
                    }
                }
                writer.WriteObjectEnd();

                return;
            }
        }