why does the Xdocument give me a utf16 declaration?

后端 未结 3 2016
慢半拍i
慢半拍i 2021-02-05 02:45

i\'m creating a XDocument like this:

XDocument doc = new XDocument(
new XDeclaration(\"1.0\", \"utf-8\", \"yes\"));

when i save the document li

3条回答
  •  自闭症患者
    2021-02-05 02:59

    Very good answer using inheritance, just remember to override the initializer

       public class Utf8StringWriter : StringWriter
        {
            public Utf8StringWriter(StringBuilder sb) : base (sb)
            {
            }
            public override Encoding Encoding { get { return Encoding.UTF8; } }
        }
    

提交回复
热议问题