protected override void WriteTextNode(XmlDictionaryReader reader, bool attribute)
{
Type type = reader.ValueType;
if (type == typeof(string))
{
XmlDictionaryString value;
if (reader.TryGetValueAsDictionaryString(out value))
{
WriteString(value);
}
else
{
if (reader.CanReadValueChunk)
{
if (_chars == null)
{
_chars = new char[256];
}
int count;
while ((count = reader.ReadValueChunk(_chars, 0, _chars.Length)) > 0)
{
this.WriteChars(_chars, 0, count);
}
}
else
{
WriteString(reader.Value);
}
}
if (!attribute)
{
reader.Read();
}
}
else if (type == typeof(byte[]))
{
if (reader.CanReadBinaryContent)
{
// Its best to read in buffers that are a multiple of 3 so we don't break base64 boundaries when converting text
if (_bytes == null)
{
_bytes = new byte[384];
}
int count;
while ((count = reader.ReadValueAsBase64(_bytes, 0, _bytes.Length)) > 0)
{
this.WriteBase64(_bytes, 0, count);
}
}
else
{
WriteString(reader.Value);
}
if (!attribute)
{
reader.Read();
}
}
else if (type == typeof(int))
WriteValue(reader.ReadContentAsInt());
else if (type == typeof(long))
WriteValue(reader.ReadContentAsLong());
else if (type == typeof(bool))
WriteValue(reader.ReadContentAsBoolean());
else if (type == typeof(double))
WriteValue(reader.ReadContentAsDouble());
else if (type == typeof(DateTime))
WriteValue(reader.ReadContentAsDateTimeOffset().DateTime);
else if (type == typeof(float))
WriteValue(reader.ReadContentAsFloat());
else if (type == typeof(decimal))
WriteValue(reader.ReadContentAsDecimal());
else if (type == typeof(UniqueId))
WriteValue(reader.ReadContentAsUniqueId());
else if (type == typeof(Guid))
WriteValue(reader.ReadContentAsGuid());
else if (type == typeof(TimeSpan))
WriteValue(reader.ReadContentAsTimeSpan());
else
WriteValue(reader.ReadContentAsObject());
}