// Token: 0x06015707 RID: 87815 RVA: 0x0056FC6C File Offset: 0x0056DE6C private static void WriteValue(object obj, JsonWriter writer, bool writer_is_private, int depth) { if (depth > JsonMapper.max_nesting_depth) { throw new JsonException(string.Format("Max allowed object depth reached while trying to export from type {0}", obj.GetType())); } if (obj == null) { writer.Write(null); return; } if (obj is IJsonWrapper) { if (writer_is_private) { writer.TextWriter.Write(((IJsonWrapper)obj).ToJson()); } else { ((IJsonWrapper)obj).ToJson(writer); } return; } if (obj is string) { writer.Write((string)obj); return; } if (obj is double) { writer.Write((double)obj); return; } if (obj is int) { writer.Write((int)obj); return; } if (obj is bool) { writer.Write((bool)obj); return; } if (obj is long) { writer.Write((long)obj); return; } if (obj is Array) { writer.WriteArrayStart(); IEnumerator enumerator = ((Array)obj).GetEnumerator(); try { while (enumerator.MoveNext()) { object obj2 = enumerator.Current; JsonMapper.WriteValue(obj2, writer, writer_is_private, depth + 1); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } writer.WriteArrayEnd(); return; } if (obj is IList) { writer.WriteArrayStart(); IEnumerator enumerator2 = ((IList)obj).GetEnumerator(); try { while (enumerator2.MoveNext()) { object obj3 = enumerator2.Current; JsonMapper.WriteValue(obj3, writer, writer_is_private, depth + 1); } } finally { IDisposable disposable2; if ((disposable2 = (enumerator2 as IDisposable)) != null) { disposable2.Dispose(); } } writer.WriteArrayEnd(); return; } if (obj is IDictionary) { writer.WriteObjectStart(); IDictionaryEnumerator enumerator3 = ((IDictionary)obj).GetEnumerator(); try { while (enumerator3.MoveNext()) { object obj4 = enumerator3.Current; DictionaryEntry dictionaryEntry = (DictionaryEntry)obj4; writer.WritePropertyName((string)dictionaryEntry.Key); JsonMapper.WriteValue(dictionaryEntry.Value, writer, writer_is_private, depth + 1); } } finally { IDisposable disposable3; if ((disposable3 = (enumerator3 as IDisposable)) != null) { disposable3.Dispose(); } } writer.WriteObjectEnd(); return; } Type type = obj.GetType(); if (JsonMapper.custom_exporters_table.ContainsKey(type)) { ExporterFunc exporterFunc = JsonMapper.custom_exporters_table[type]; exporterFunc(obj, writer); return; } if (JsonMapper.base_exporters_table.ContainsKey(type)) { ExporterFunc exporterFunc2 = JsonMapper.base_exporters_table[type]; exporterFunc2(obj, writer); return; } if (obj is Enum) { Type underlyingType = Enum.GetUnderlyingType(type); if (underlyingType == typeof(long) || underlyingType == typeof(uint) || underlyingType == typeof(ulong)) { writer.Write((ulong)obj); } else { writer.Write((int)obj); } return; } JsonMapper.AddTypeProperties(type); IList <PropertyMetadata> list = JsonMapper.type_properties[type]; writer.WriteObjectStart(); foreach (PropertyMetadata propertyMetadata in list) { if (propertyMetadata.IsField) { writer.WritePropertyName(propertyMetadata.Info.Name); JsonMapper.WriteValue(((FieldInfo)propertyMetadata.Info).GetValue(obj), writer, writer_is_private, depth + 1); } else { PropertyInfo propertyInfo = (PropertyInfo)propertyMetadata.Info; if (propertyInfo.CanRead) { writer.WritePropertyName(propertyMetadata.Info.Name); JsonMapper.WriteValue(propertyInfo.GetValue(obj, null), writer, writer_is_private, depth + 1); } } } writer.WriteObjectEnd(); }