Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 9c1467e

Browse files
committed
Make XmlReaderSettings and XmlWriterSettings public & customizable
1 parent ae67028 commit 9c1467e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/ServiceStack.Text/XmlSerializer.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ namespace ServiceStack.Text
99
{
1010
public class XmlSerializer
1111
{
12-
private static readonly XmlWriterSettings XWSettings = new XmlWriterSettings();
13-
private static readonly XmlReaderSettings XRSettings = new XmlReaderSettings();
12+
public static readonly XmlWriterSettings XmlWriterSettings = new XmlWriterSettings();
13+
public static readonly XmlReaderSettings XmlReaderSettings = new XmlReaderSettings();
1414

1515
public static XmlSerializer Instance = new XmlSerializer();
1616

1717
public XmlSerializer(bool omitXmlDeclaration = false, int maxCharsInDocument = 1024 * 1024)
1818
{
19-
XWSettings.Encoding = PclExport.Instance.GetUTF8Encoding(false);
20-
XWSettings.OmitXmlDeclaration = omitXmlDeclaration;
21-
XRSettings.MaxCharactersInDocument = maxCharsInDocument;
19+
XmlWriterSettings.Encoding = PclExport.Instance.GetUTF8Encoding(false);
20+
XmlWriterSettings.OmitXmlDeclaration = omitXmlDeclaration;
21+
XmlReaderSettings.MaxCharactersInDocument = maxCharsInDocument;
2222

2323
//Prevent XML bombs by default: https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
24-
XRSettings.DtdProcessing = DtdProcessing.Prohibit;
24+
XmlReaderSettings.DtdProcessing = DtdProcessing.Prohibit;
2525
}
2626

2727
private static object Deserialize(string xml, Type type)
2828
{
2929
try
3030
{
3131
var stringReader = new StringReader(xml);
32-
using (var reader = XmlReader.Create(stringReader, XRSettings))
32+
using (var reader = XmlReader.Create(stringReader, XmlReaderSettings))
3333
{
3434
var serializer = new DataContractSerializer(type);
3535
return serializer.ReadObject(reader);
@@ -76,7 +76,7 @@ public static string SerializeToString<T>(T from)
7676
{
7777
using (var ms = MemoryStreamFactory.GetStream())
7878
{
79-
using (var xw = XmlWriter.Create(ms, XWSettings))
79+
using (var xw = XmlWriter.Create(ms, XmlWriterSettings))
8080
{
8181
var serializer = new DataContractSerializer(from.GetType());
8282
serializer.WriteObject(xw, from);
@@ -97,7 +97,7 @@ public static void SerializeToWriter<T>(T value, TextWriter writer)
9797
{
9898
try
9999
{
100-
using (var xw = XmlWriter.Create(writer, XWSettings))
100+
using (var xw = XmlWriter.Create(writer, XmlWriterSettings))
101101
{
102102
var serializer = new DataContractSerializer(value.GetType());
103103
serializer.WriteObject(xw, value);
@@ -112,7 +112,7 @@ public static void SerializeToWriter<T>(T value, TextWriter writer)
112112
public static void SerializeToStream(object obj, Stream stream)
113113
{
114114
if (obj == null) return;
115-
using (var xw = XmlWriter.Create(stream, XWSettings))
115+
using (var xw = XmlWriter.Create(stream, XmlWriterSettings))
116116
{
117117
var serializer = new DataContractSerializer(obj.GetType());
118118
serializer.WriteObject(xw, obj);

0 commit comments

Comments
 (0)