private WriteToken ( JsonReader reader, bool writeChildren, bool writeDateConstructorAsDate, bool writeComments ) : void | ||
reader | JsonReader | |
writeChildren | bool | |
writeDateConstructorAsDate | bool | |
writeComments | bool | |
Résultat | void |
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);
}
}
}
private JToken CreateJToken(JsonReader reader, JsonContract contract) { ValidationUtils.ArgumentNotNull(reader, "reader"); if (contract != null && contract.UnderlyingType == typeof (JRaw)) { return JRaw.Create(reader); } else { JToken token; using (JTokenWriter writer = new JTokenWriter()) { writer.WriteToken(reader); token = writer.Token; } return token; } }