简体   繁体   中英

C# custom configuration versioning

I have implemented a custom file configuration, that uses custom sections, using C#. The main issue i have is with implementing some kind of version aware configuration loader. Confgiurations change, but we need to make them usable anyway. Is there any documentation that points in the direction of having some kind of versioning in configurations?

I'll give you two examples on what my issues are: - key["key1"] changes from boolean type to int type. - key["key2"] mandatory ceases to exist

thanks.

You could have the concept of default values for each setting. If you introduce a new setting and an old config file doesn't have it then it would use the default value. Similarly, if you remove a setting from the code then its existence in the config file would be harmless, it would just be ignored.

If you want to change how a given setting works (the type or the format) then it's a little more tricky. You could try to parse the value and if it's not in the right format you could ignore it and use the default value.

My tendency would be to add some kind of version header to the configs and keep a history of their schemas in the app. It could be troublesome in some ways, but at least you don't have to guess what an old value meant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM