我面临的问题是在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
之外的所有内容,因为"I“不知道它看起来像什么。
我遍历PhoneCodes
,如下所示:
foreach (var phoneCode in value.PhoneCodes)
{
current += GetHashString(phoneCode.Code);
}
但是,我如何才能循环Enums
/获取它的子级呢?
我尝试过将Enums
转换为Json对象,但没有成功
发布于 2019-03-27 10:46:38
尝试以下操作:
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);
}
}
https://stackoverflow.com/questions/55374935
复制