forked from SoDOff-Project/sodoff
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.Xml.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace sodoff.Util;
|
||||
public class XmlUtil {
|
||||
@ -9,9 +10,13 @@ public class XmlUtil {
|
||||
return (T)serializer.Deserialize(reader);
|
||||
}
|
||||
|
||||
private class Utf8StringWriter : StringWriter {
|
||||
public override Encoding Encoding => Encoding.UTF8;
|
||||
}
|
||||
|
||||
public static string SerializeXml<T>(T xmlObject) {
|
||||
var serializer = new XmlSerializer(typeof(T));
|
||||
using (var writer = new StringWriter()) {
|
||||
using (var writer = new Utf8StringWriter()) {
|
||||
serializer.Serialize(writer, xmlObject);
|
||||
return writer.ToString();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user