Search code examples
c#.net-2.0settingsinterfaceapplication-settings

C# multiple settings files with same interface


I'm trying to create a program with two (or more) discrete sets of settings, that both conform to the same interface. Particularly I'd like to do something like the following, using designer generated settings:

IMySettings settings = Properties.A;
Console.WriteLine(settings.Greeting);
settings = Properties.B;
Console.WriteLine(settings.Greeting);

This would be trivial with Go's interfaces because any class(?) that provides the methods can be assigned, but how can I implement this in C#, with its strict interface implementation rules?

Note: C#/.NET 2.0


Solution

  • The Properties.Settings class generated in VS is not going to let you do this. Consider defining a simple DTO class and marking it up with XmlAttribute so that you can easily deserialize it.