//GEMErrorCode是类名
var type = typeof(GEMErrorCode);
FieldInfo[] fis = type.GetFields();
var constants = "";
var constValue = "";
foreach (var fieldInfo in fis)
{
constants = fieldInfo.Name.ToString();
constValue = fieldInfo.GetValue(constants).ToString();
//文档中有两个value值是一样的
if (constants == "ERR_GEM_ERROR_BASE")
{
continue;
}
//public const int OK = 0;我们将0作为key值,ok作为value值
GEMErrorCode.DicErrorCode.Add(constValue, constants);
Console.WriteLine("key:" + constValue + "\t" + " value:" + constants);
}
//这里的0是key值
Console.WriteLine(GEMErrorCode.DicErrorCode[0.ToString()]);