C# – How to read a custom class from app.config with an automatic loader

It’s tedious to manually map settings from appSettings to your own class. You may have looked for ways to load your own custom class. The official documentation that explains how to do this is overly complicated. They would have you inheriting from ConfigurationSection, etc…, which is way too much effort. Why bother with all of … Read more C# – How to read a custom class from app.config with an automatic loader

C# – Use Convert.ChangeType to convert string to any type

You can use Convert.ChangeType() to convert from a string to any type, like this: Normally you’d call the specific type converter method, like Convert.ToBoolean(“true”). However, sometimes it makes sense to use the generalized type converter method – Convert.ChangeType() – instead of hardcoding the calls to specific type converter methods. I’ll show an example of when … Read more C# – Use Convert.ChangeType to convert string to any type

How to modify app.config at runtime

When you try to modify the app.config at runtime, if you don’t do it right, you’ll run into a few problems: You’ll get the following exception: System.Configuration.ConfigurationErrorsException: The configuration is read only. The updated value isn’t persisted. When you re-open your program, the value you changed is still the old value. This article will show … Read more How to modify app.config at runtime

How to parse a comma-separated string from app.config

I had to parse a list of comma-separated HTTP Response Codes from the app.config file and use them to retry HTTP POST requests if the response code was contained in that list. This article explains how to parse a list of comma-separated values from the app.config and put them into a HashSet so it can … Read more How to parse a comma-separated string from app.config