Created
March 18, 2025 17:23
-
-
Save dontpaniclabsgists/891aae1efddec611e86ac82f4675c6da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Utf8StringWriter : StringWriter | |
{ | |
public override Encoding Encoding => Encoding.UTF8; | |
} | |
``` | |
Using this custom writer, we can write our XML in the same way. | |
```C# | |
XmlSerializer serializer = new XmlSerializer(typeof(Person)); | |
using (Utf8StringWriter writer = new Utf8StringWriter()) | |
{ | |
serializer.Serialize(writer, person, namespaces); | |
Console.WriteLine(writer.ToString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment