private void SerializeJsonObject(TextWriter writer, Stack <RuntimeObject> stack, RuntimeObject value) { bool hasEntries = false; string prependString = String.Join("", stack.Select(v => indentString).ToArray()); if (stack.Contains(value)) { throw new EcmaTypeErrorException(InternalString.Error.CircularJsonObject); } stack.Push(value); writer.Write("{"); List <EcmaPropertyEntry> entries = new List <EcmaPropertyEntry>(); if (propertyList != null) { entries.AddRange(propertyList.Select(v => new EcmaPropertyEntry(v, value.Get(v)))); } else { entries.AddRange(value.GetEnumerableOwnProperties(false)); } foreach (EcmaPropertyEntry e in entries) { EcmaValue v = TransformValue(value, e.Key, e.Value); if (v.Type != EcmaValueType.Undefined) { if (hasEntries) { writer.Write(","); } hasEntries = true; if (indentString != String.Empty) { writer.Write(Environment.NewLine); writer.Write(prependString); writer.Write(indentString); } WriteString(writer, e.Key.ToString()); writer.Write(":"); if (indentString != String.Empty) { writer.Write(" "); } WritePropertyValue(writer, stack, v); } } if (hasEntries && indentString != String.Empty) { writer.Write(Environment.NewLine); writer.Write(prependString); } writer.Write("}"); stack.Pop(); }