mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 08:18:49 -07:00
use utf-8 in xml headers from SerializeXml
we use ascii/utf-8 (not utf-16) encoding in files and network data so XML header should be always `<?xml version="1.0" encoding="utf-8"?>`
This commit is contained in:
parent
ea3de10100
commit
7e5a90ba87
@ -1,5 +1,6 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace sodoff.Util;
|
namespace sodoff.Util;
|
||||||
public class XmlUtil {
|
public class XmlUtil {
|
||||||
@ -9,9 +10,13 @@ public class XmlUtil {
|
|||||||
return (T)serializer.Deserialize(reader);
|
return (T)serializer.Deserialize(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class Utf8StringWriter : StringWriter {
|
||||||
|
public override Encoding Encoding => Encoding.UTF8;
|
||||||
|
}
|
||||||
|
|
||||||
public static string SerializeXml<T>(T xmlObject) {
|
public static string SerializeXml<T>(T xmlObject) {
|
||||||
var serializer = new XmlSerializer(typeof(T));
|
var serializer = new XmlSerializer(typeof(T));
|
||||||
using (var writer = new StringWriter()) {
|
using (var writer = new Utf8StringWriter()) {
|
||||||
serializer.Serialize(writer, xmlObject);
|
serializer.Serialize(writer, xmlObject);
|
||||||
return writer.ToString();
|
return writer.ToString();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user