-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Use XmlWriter.Create instead of XmlTextWriter #54949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
4487a92
12c3bae
e3d3bf4
2f43131
a10731a
0c0f2b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,9 +317,10 @@ public void Serialize(TextWriter textWriter, object? o) | |
| [RequiresUnreferencedCode(TrimSerializationWarning)] | ||
| public void Serialize(TextWriter textWriter, object? o, XmlSerializerNamespaces? namespaces) | ||
| { | ||
| XmlTextWriter xmlWriter = new XmlTextWriter(textWriter); | ||
| xmlWriter.Formatting = Formatting.Indented; | ||
| xmlWriter.Indentation = 2; | ||
| //XmlTextWriter xmlWriter = new XmlTextWriter(textWriter); | ||
| //xmlWriter.Formatting = Formatting.Indented; | ||
| //xmlWriter.Indentation = 2; | ||
| XmlWriter xmlWriter = XmlWriter.Create(textWriter, new XmlWriterSettings() { CheckCharacters = true, IndentChars = " ", Indent = true }); | ||
| Serialize(xmlWriter, o, namespaces); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why explicitly set CheckCharacters and IndentChars? You are seeting them to their default values. |
||
| } | ||
|
|
||
|
|
@@ -332,9 +333,10 @@ public void Serialize(Stream stream, object? o) | |
| [RequiresUnreferencedCode(TrimSerializationWarning)] | ||
| public void Serialize(Stream stream, object? o, XmlSerializerNamespaces? namespaces) | ||
| { | ||
| XmlTextWriter xmlWriter = new XmlTextWriter(stream, null); | ||
| xmlWriter.Formatting = Formatting.Indented; | ||
| xmlWriter.Indentation = 2; | ||
| //XmlTextWriter xmlWriter = new XmlTextWriter(stream, null); | ||
| //xmlWriter.Formatting = Formatting.Indented; | ||
| //xmlWriter.Indentation = 2; | ||
StephenMolloy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| XmlWriter xmlWriter = XmlWriter.Create(stream, new XmlWriterSettings() { CheckCharacters = true, IndentChars = " ", Indent = true }); | ||
| Serialize(xmlWriter, o, namespaces); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for this, skip setting values to the defaults. |
||
| } | ||
|
|
||
|
|
@@ -421,10 +423,11 @@ private XmlMapping GetMapping() | |
| [RequiresUnreferencedCode(TrimDeserializationWarning)] | ||
| public object? Deserialize(Stream stream) | ||
| { | ||
| XmlTextReader xmlReader = new XmlTextReader(stream); | ||
| xmlReader.WhitespaceHandling = WhitespaceHandling.Significant; | ||
| xmlReader.Normalization = true; | ||
| xmlReader.XmlResolver = null; | ||
| //XmlTextReader xmlReader = new XmlTextReader(stream); | ||
| //xmlReader.WhitespaceHandling = WhitespaceHandling.Significant; | ||
| //xmlReader.Normalization = true; | ||
| //xmlReader.XmlResolver = null; | ||
StephenMolloy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| XmlReader xmlReader = XmlReader.Create(stream, new XmlReaderSettings() { IgnoreWhitespace = true }); | ||
| return Deserialize(xmlReader, null); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.