StringWriter Encoding property is actually not that useful since it is based on a StringBuilder that creates .Net strings .. Net strings are encoded inside utf16, but these are implementation details that you need not worry about. Encoding is just a property inherited from TextWriter , because TextWriter can potentially write objects where the encoding matters ( Stream , byte[] , ...).
You end up with a plain old string . The encoding that you will use to serialize this string later is still not fixed, and if you use the MongoDb client implementation that takes the string as an argument, this is not even your problem!
On the other hand, overriding the getter of the Encoding property will not change the encoding method, even if the encoding was actually involved in StringWriter
Falanwe
source share