Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,18 @@ public override unsafe void WriteRaw(string data)
_textPos = _bufPos;
}

internal override unsafe void WriteRaw(ReadOnlySpan<char> value)
{
if (_trackTextContent && _inTextContent) { ChangeTextContentMark(false); }

fixed (char* pSrcBegin = value)
{
WriteRawWithCharChecking(pSrcBegin, pSrcBegin + value.Length);
}

_textPos = _bufPos;
}

// Flush all bytes in the buffer to output and close the output stream or writer.
public override void Close()
{
Expand Down Expand Up @@ -2125,6 +2137,12 @@ public override void WriteRaw(string data)
base.WriteRaw(data);
}

internal override void WriteRaw(ReadOnlySpan<char> value)
{
_mixedContent = true;
base.WriteRaw(value);
}

public override void WriteBase64(byte[] buffer, int index, int count)
{
_mixedContent = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,18 @@ namespace System.Xml
_textPos = _bufPos;
}

internal override unsafe void WriteRaw(ReadOnlySpan<char> value)
{<#
#><#= SetTextContentMark(3, false) #>

fixed (char* pSrcBegin = value)
{
WriteRawWithCharChecking(pSrcBegin, pSrcBegin + value.Length);
}

_textPos = _bufPos;
}

// Flush all bytes in the buffer to output and close the output stream or writer.
public override void Close()
{
Expand Down Expand Up @@ -2181,6 +2193,12 @@ namespace System.Xml
base.WriteRaw(data);
}

internal override void WriteRaw(ReadOnlySpan<char> value)
{
_mixedContent = true;
base.WriteRaw(value);
}

public override void WriteBase64(byte[] buffer, int index, int count)
{
_mixedContent = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ public override void WriteRaw(string data)
WriteString(data);
}

// Forward call to WriteString(string).
internal virtual void WriteRaw(ReadOnlySpan<char> value)
{
WriteString(value.ToString());
}

// Override in order to handle Xml simple typed values and to pass resolver for QName values
public override void WriteValue(object value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,16 @@ public override unsafe void WriteRaw(string data)
_textPos = _bufPos;
}

internal override unsafe void WriteRaw(ReadOnlySpan<char> value)
{
fixed (char* pSrcBegin = value)
{
WriteRawWithCharChecking(pSrcBegin, pSrcBegin + value.Length);
}

_textPos = _bufPos;
}

// Flush all bytes in the buffer to output and close the output stream or writer.
public override void Close()
{
Expand Down Expand Up @@ -1985,6 +1995,12 @@ public override void WriteRaw(string data)
base.WriteRaw(data);
}

internal override void WriteRaw(ReadOnlySpan<char> value)
{
_mixedContent = true;
base.WriteRaw(value);
}

public override void WriteBase64(byte[] buffer, int index, int count)
{
_mixedContent = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,31 @@ public override void WriteRaw(string data)
}
}

internal void WriteRaw(ReadOnlySpan<char> data)
{
try
{
AdvanceState(Token.RawData);
if (SaveAttrValue)
{
_attrValueCache!.WriteRaw(data.ToString());
}
else if (_rawWriter is not null)
{
_rawWriter.WriteRaw(data);
}
else
{
_writer.WriteRaw(data.ToString());
}
}
catch
{
_currentState = State.Error;
throw;
}
}

public override void WriteBase64(byte[] buffer, int index, int count)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,14 @@ protected void WriteTypedPrimitive(string? name, string? ns, object o, bool xsiT
Debug.Assert(!span.Slice(0, charsWritten).ContainsAny(escapeChars), "Primitive value contains illegal xml char.");
#endif
//all the primitive types except string and XmlQualifiedName writes to the buffer
_w.WriteRaw(_primitivesBuffer, 0, charsWritten);
if (_w is XmlWellFormedWriter wellFormedWriter)
{
wellFormedWriter.WriteRaw(_primitivesBuffer.AsSpan(0, charsWritten));
}
else
{
_w.WriteRaw(_primitivesBuffer, 0, charsWritten);
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ public static void Xml_DecimalAsRoot()
}
}

[Fact]
public static void Xml_DecimalArrayAsRoot()
{
decimal[] values = new decimal[] { (decimal)-1.2, (decimal)0, (decimal)2.3, decimal.MinValue, decimal.MaxValue };
string serialized = Serialize(values, string.Empty, skipStringCompare: true);

Assert.Contains("<decimal>-1.2</decimal>", serialized);
Assert.Contains("<decimal>0</decimal>", serialized);
Assert.Contains("<decimal>2.3</decimal>", serialized);
Assert.Contains($"<decimal>{decimal.MinValue.ToString(CultureInfo.InvariantCulture)}</decimal>", serialized);
Assert.Contains($"<decimal>{decimal.MaxValue.ToString(CultureInfo.InvariantCulture)}</decimal>", serialized);

Assert.Equal(values, SerializeAndDeserialize(values, string.Empty, skipStringCompare: true));
}

[Fact]
public static void Xml_DoubleAsRoot()
{
Expand Down