internal override void WriteToken(JsonReader reader, bool writeChildren, bool writeDateConstructorAsDate, bool writeComments)
{
JTokenReader tokenReader = reader as JTokenReader;
// closing the token wrather than reading then writing it doesn't lose some type information, e.g. Guid, byte[], etc
if (tokenReader != null && writeChildren && writeDateConstructorAsDate && writeComments)
{
if (tokenReader.TokenType == JsonToken.None)
{
if (!tokenReader.Read())
{
return;
}
}
JToken value = tokenReader.CurrentToken.CloneToken();
if (_parent != null)
{
_parent.Add(value);
_current = _parent.Last;
// if the writer was in a property then move out of it and up to its parent object
if (_parent.Type == JTokenType.Property)
{
_parent = _parent.Parent;
InternalWriteValue(JsonToken.Null);
}
}
else
{
_current = value;
if (_token == null && _value == null)
{
_token = value as JContainer;
_value = value as JValue;
}
}
tokenReader.Skip();
}
else
{
base.WriteToken(reader, writeChildren, writeDateConstructorAsDate, writeComments);
}
}
}