在 C# 中将定义的掩码标识符评估为其实际值

Evaluate defined Mask Identifier to its Actual Value in 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 常量。

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