I'm curious if it's possible to undo changes I've made to ConfigurationSection in run-time. I don't want to create lots of variables & set current values, so that when I want to undo them, I can just set them back. I need a simpler way, a method I suppose? Can anyone help me?
Asked
Active
Viewed 163 times
3 Answers
1
Have you considered using serialization? You could serialize ConfiguartionSection and then deserialize it to undo. Here are some tips.

zmilojko
- 2,125
- 17
- 27
-
can you give some code tutorial? it's just that I've never had an opportunity to work with it... have no idea how to do this – GaaRa Nov 07 '11 at 13:50
1
IMO, you can write it in several approaches. For an instance if you are after to change your application settings at run-time, you can store them in a better place like database in lieu of configuration file and a simple versioning system to log a history from user changes.
1
You can implement the Command Pattern. It is ideal for your situation. You can use StreamReader and StreamWriter to read and write your backup files.
interface ICommandPattern {
void Execute();
void Undo();
}
class SaveConfigurationPattern : ICommandPattern {
string _backupFileName;
public void Execute()
{
// serialize your original and save to the backup file name
// make changes and save to your config file
}
public void Undo()
{
// copy your backup file over the configuration file
}
}
you can store an array of instances of the SaveConfigurationPattern
and allow for multi-level undo and redo operations.

Charles Lambert
- 5,042
- 26
- 47