Search code examples
.netconfigurationsettingsapplication-settings

What to store at application Settings, numeric / string representations or objects?


I've been thinking for a while on what to store at the Project Settings, objects or numeric/string representations of those objects to set a rule and avoid thinking on this at the future so I want to take the best approach.

On one side storing object representations grants you that what is stored is valid and saves you from doing conversions each time you access them. You only need objects with the attribute.

At the other side storing the numeric/string representation of an object eases the editing of the setting because at the end the user will be entering numeric or string information.

What do you do with this issue?


Solution

  • Interesting question. Personally, I try not to store complex objects in the settings, because (in my opinion, which is subjective) it makes the code harder to understand for a maintenance programmer. I tend to use the simple types (sting, int, etc) in the settings.

    In cases where I have a complex object with a lot of properties, then I may store the property values in the settings file.

    For example, let's say you have a custom ErrorLoggingModule that has properties like "DatabaseConnectionString", "ApplicationID". (We use something similar to this and each application we write gets a unique application ID. This gives us a central error logging database for ALL our applications. )

    I'd store each of those values in the settings file, and have one routine for logging errors. This routine would create a new ErrorLoggingModule object, read the appropriate settings from the file, and apply the values from the settings file to the appropriate properties, then do whatever I need to do with it.