我面临的问题是遍历object
。
我的Resource类的一部分看起来像这样:
public List<PhoneCodeInfo> PhoneCodes { get; set; }
public List<CountryInfo> Countries { get; set; }
public List<BrandDetail> Brands { get; set; }
public List<FileTypeDetail> FileTypes { get; set; }
public object Enums { get; set; } // <- is the problem
我可以轻松遍历除Enums
之外的所有内容,因为“我”不知道它是什么样。
我像这样遍历PhoneCodes
foreach (var phoneCode in value.PhoneCodes)
{
current += GetHashString(phoneCode.Code);
}
但是我该如何循环Enums
或获取其子项。
我尝试将Enums
转换为Json对象,但是没有运气
答案 0 :(得分:1)
尝试以下操作:
public enum Test
{
One,
Two,
Three,
Four
}
static void Main(string[] args)
{
string[] names = Enum.GetNames(typeof(Test)).ToArray();
foreach (var name in names)
{
int value = (int)Enum.Parse(typeof(Test),name);
}
}