I have a very simple XML Preferences file, which I read into a property C_PREFERENCES_XML in a module in my application. I am then parsing that XML file into a dictionary, which contains the key/value pairs in the file. All good.
The XML file nodes look like this:
<Preference name="P_LOG_VERBOSITY" value="True"/>
<Preference name="P_REMOTE_SERVER_HEARTBEAT_INTERVAL" value="0"/>
<Preference name="P_REMOTE_SERVER_IP" value="192.168.001.220"/>
<Preference name="P_REMOTE_SERVER_PORT" value="8888"/>
<Preference name="P_LOCAL_SERVER_IP" value="192.168.1.221"/>
<Preference name="P_LOCAL_SERVER_PORT" value="8889"/>
Each of the name items is the same name as one of the properties in the module:

What I want to do is move the values from the XML file into the appropriate properties. I think the way to do this is with introspection, but I’m really not clear on how that works for something like this. I’ve read the introspection docs three times, and looked at the example project but I’m not quite getting how I would:
- Get the names of all the properties in one module only
- use that name to assign a value from the dictionary to the corresponding key (which happens to be the name of the property).
Is this possible? If so, how?
I’m trying to avoid a long switch/case or if/then statement that has to be manually edited each time i add a new preference to the app, which is going to start happening at a rapid pace. The idea is to build something that’s flexible, so that I don’t need to do that.