I have a set of custom XML configuration management classes in .NET.
There are two configuration scopes in my application:
User: the setting applies to the user regardless of the account she's logged into. Stored in a XML config file in the user's directory.
User/Account: the setting applies to the user when logged into a particular account. Stored in a XML config file in the user's directory under an account specific sub-directory.
The two XML documents have the same structure and can be modified by hand. When the application starts up, I read the XML config from the user's profile and the XML config from the User/Account directory. I then merge the two XML documents into a single XDocument and then deserialize the XML into objects modeled after the XDocument's sections. If there is a User/Account-level setting present, it should override the User-level setting. Example:
User file:
<FileSettings>
<DownloadPath>C:\downloads</DownloadPath>
<UploadPath>C:\uploads</UploadPath>
</FileSettings>
User/Account file for account XYZ:
<FileSettings>
<DownloadPath>C:\newlocation\xyz\mystuff</DownloadPath>
</FileSettings>
Result after merge:
<FileSettings>
<DownloadPath>C:\newlocation\xyz\mystuff</DownloadPath>
<UploadPath>C:\uploads</UploadPath>
</FileSettings>
In the above example, a FileSettings object with 2 properties - DownloadPath and UploadPath will be instantiated from the section.
Here's my issue: I have no idea which config file (i.e., scope) the DownloadPath and UploadPath came from. As a result, when the object needs to serialize again, it doesn't know which properties go in which file.
Question: What's the best way to store the "source," on a property-by-property basis, so that I can ensure a setting gets written to the same config file that it was read from?
Thanks.