Skip to content
Merged
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 @@ -317,7 +317,7 @@ public void Serialize(TextWriter textWriter, object? o)
[RequiresUnreferencedCode(TrimSerializationWarning)]
public void Serialize(TextWriter textWriter, object? o, XmlSerializerNamespaces? namespaces)
{
XmlWriter xmlWriter = XmlWriter.Create(textWriter, new XmlWriterSettings() { Indent = true });
XmlWriter xmlWriter = XmlWriter.Create(textWriter);
Serialize(xmlWriter, o, namespaces);
}

Expand All @@ -330,7 +330,7 @@ public void Serialize(Stream stream, object? o)
[RequiresUnreferencedCode(TrimSerializationWarning)]
public void Serialize(Stream stream, object? o, XmlSerializerNamespaces? namespaces)
{
XmlWriter xmlWriter = XmlWriter.Create(stream, new XmlWriterSettings() { Indent = true });
XmlWriter xmlWriter = XmlWriter.Create(stream);
Serialize(xmlWriter, o, namespaces);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,21 @@ public static void Xml_WithXElementWithNestedXElement()
VerifyXElementObject((XElement)original.e1.FirstNode, (XElement)actual.e1.FirstNode);
}

[Fact]
public static void Xml_WithXElementWithEmptyNestedElement()
{
var original = new WithXmlElement(true);
original.xml.InnerXml = "<empty></empty>";

MemoryStream ms = new MemoryStream();
new XmlSerializer(typeof(WithXmlElement)).Serialize(ms, original);

ms.Position = 0;
StreamReader sr = new StreamReader(ms);
string output = sr.ReadToEnd();
Assert.Contains("<empty></empty>", output); // Self-closed, or completely empty is OK. No added space.
}

[Fact]
public static void Xml_WithArrayOfXElement()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,19 @@ public WithXElement(bool init)
}
}

public class WithXmlElement
{
public XmlElement xml;

public WithXmlElement() { }

public WithXmlElement(bool init)
{
var doc = new XmlDocument();
xml = doc.CreateElement("Element1");
}
}

public class WithXElementWithNestedXElement
{
public XElement e1;
Expand Down