public static void WriteRuntimeContainer(SimpleJson.Writer writer, Container container, bool withoutName = false) { writer.WriteArrayStart(); foreach (var c in container.content) { WriteRuntimeObject(writer, c); } // Container is always an array [...] // But the final element is always either: // - a dictionary containing the named content, as well as possibly // the key "#" with the count flags // - null, if neither of the above var namedOnlyContent = container.namedOnlyContent; var countFlags = container.countFlags; var hasNameProperty = container.name != null && !withoutName; bool hasTerminator = namedOnlyContent != null || countFlags > 0 || hasNameProperty; if (hasTerminator) { writer.WriteObjectStart(); } if (namedOnlyContent != null) { foreach (var namedContent in namedOnlyContent) { var name = namedContent.Key; var namedContainer = namedContent.Value as Container; writer.WritePropertyStart(name); WriteRuntimeContainer(writer, namedContainer, withoutName: true); writer.WritePropertyEnd(); } } if (countFlags > 0) { writer.WriteProperty("#f", countFlags); } if (hasNameProperty) { writer.WriteProperty("#n", container.name); } if (hasTerminator) { writer.WriteObjectEnd(); } else { writer.WriteNull(); } writer.WriteArrayEnd(); }