private void ReadChildContents( EmberReader reader, ElementType actualType, int number, ref Element child, out RetrievalState childRetrievalState) { reader.AssertInnerNumber(InnerNumber.Set); if (child != null) { childRetrievalState = child.ReadContents(reader, actualType); } else { using (var stream = new MemoryStream()) using (var writer = new EmberWriter(stream)) { // Since EmberReader checks that every end of a container is matched by a start, we need to write // this dummy here. writer.WriteStartSet(GlowNode.Contents.OuterId); var identifier = reader.CopyToEndContainer(writer, GlowNodeContents.Identifier.OuterId) as string; if (identifier != null) { writer.Flush(); stream.Position = 0; using (var contentsReader = new EmberReader(stream)) { contentsReader.Read(); // Read what we have written with WriteStartSet above var newPolicy = this.childrenRetrievalPolicy == ChildrenRetrievalPolicy.All ? ChildrenRetrievalPolicy.All : ChildrenRetrievalPolicy.None; var context = new Context(this, number, identifier, newPolicy); child = this.ReadNewChildContents(contentsReader, actualType, context, out childRetrievalState); if (child != null) { this.children.Add(number, child); } } } else { childRetrievalState = RetrievalState.Complete; child = null; } } } }