When reading our configuration and resource files, our .Net system currently just does ConfigurationManager.AppSettings["keyToFind"] or similar and merrily goes on its way, assuming that it found what it was looking for. When we add new config we need to remember to add it to the config files manually and runtime issues are not always easy to track down if (when!) we forget.
So I thought of adding a small class as a single gateway for reading our app.config and .resx files. My first attempt simply does the same thing then checks for nulls and throws an exception, logs an error or sets a default, where appropriate, if something is not found. It works fine but I’m wondering if I’m re-inventing the wheel. Also, as far as I know I can’t make the app.config only available through this class, is that correct? So future devs are free to ignore my solution!
Is there a better (i.e., built-in or accepted standard) way of dealing with missing fields in the config files?
I’m also looking at templating the config files with T4 for consistency but I’d like a runtime check as well.
I think this is certanly already done by many others (including me) work, but it’s not that much to bother. Just do that you need for your case and forget.