Preserve formatting on Configuration.Save()

388 Views Asked by At

I have custom ConfigurationSection and call Configuration.Save() after some modifications against it:

var config = ConfigurationManager.OpenMappedExeConfiguration(
    new ExeConfigurationFileMap() { ExeConfigFilename = "My.config" },
    ConfigurationUserLevel.None);
if (config != null)
{
    // do stuff

    config.Save();
}

Currently it performs some formatting of resulting XML. For example, replaces tabs with spaces, inserts line-breaks if it thinks that it's too long (> ~130 characters), etc.

How can I preserve or control that?

1

There are 1 best solutions below

1
On BEST ANSWER

Save function internally uses the XmlUtilWriter class which is also an internal class under System.Configuration namespace. Your best change is to either try to modify the class with reflection at runtime, or go the easy way and do a serialization manually.