2017-05-07 80 views
0

我已经在我的C#代码定义为面具定义的模板标识其实际价值:评价在C#

public const uint GFDEVICE_OUTPUTS_REFRESH_ALL = 0xFFFFFFFF; 

我想用这个名字(GFDEVICE_OUTPUTS_REFRESH_ALL),而不是实际值(0xFFFFFFFF)我的配置文件,因此我需要读取掩码的常量名称并将其转换为实际的uint值。在XML CFG文件中的条目

例子:

entry ="display mask" value="GFDEVICE_OUTPUTS_REFRESH_ALL" 

当读取配置文件,我想读的字符串值GFDEVICE_OUTPUTS_REFRESH_ALL并转换为的0xFFFFFFFF UINT在运行时。
请注意我没有在我的代码中使用枚举掩码。我的面具被定义为uint常量作为上面的状态。

回答

1
<?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]);