Best practices in App.Config?

Usually, when you have the application configuration file in the application, and your application should read it.

Is it good to check at startup if this file exists and cause an error, and not continue? (Worst cases of senarios)

Or leave it to an unhandled exception manager to process it and close the application? (WPF / Winforms etc.)

Consult?

+3
source share
2 answers

A better approach would be to configure the correct default settings and work in the absence of a file. Indeed, what happens if the file is present, but some critical parameter has been deleted by the user?

, , , .

+3

- , , triing, app.config:

private static int SomeValue
{
     get
     {
         int result = 60; //Some default value
         string str = ConfigurationManager.AppSettings["SomeValue"];
         if (!String.IsNullOrEmpty(str))
         {
             Int32.TryParse(str, out result);
         }
         return result;
      }
}
+1

Source: https://habr.com/ru/post/1738924/


All Articles