Reputation: 1165
I have a mask defined in my C# code as:
public const uint GFDEVICE_OUTPUTS_REFRESH_ALL = 0xFFFFFFFF;
I would like to use that name (GFDEVICE_OUTPUTS_REFRESH_ALL
) instead of the actual value (0xFFFFFFFF
) in my config file and therefore I need to read the constant name of the mask and convert it to actual uint
value.
Example of an entry in XML cfg file:
entry ="display mask" value="GFDEVICE_OUTPUTS_REFRESH_ALL"
When reading the config file, I want to read the string value GFDEVICE_OUTPUTS_REFRESH_ALL
and convert to uint of 0xFFFFFFFF
at run-time.
Please note I am not using enums in my code for masks. My masks are defined as uint constants as state above.
Upvotes: 0
Views: 105
Reputation: 186
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="display mask" value="GFDEVICE_OUTPUTS_REFRESH_ALL=0xFFFFFFFF" />
</appSettings>
</configuration>
string value = ConfigurationManager.AppSettings["display mask"];
Dictionary<string,uint> dic = new Dictionary<string,uint>();
string key = value.split('=')[0];
uint value = Convert.ToUInt(value.split('=')[1]);
Upvotes: 1