我在我的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。
请注意,我没有在我的代码中使用枚举。我的口罩定义为上述状态。
<?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]);