C# 自定义枚举类型转换

// string to enum

EAccountRole var = (EAccountRole)Enum.Parse(typeof(EAccountRole), RoleManage.Instance.CurrentAccount.Role);

 

// enum to list

public IEnumerable<EAccountRole> RoleList
{
get
{
if (RoleManage.Instance.CurrentLoginRole == EAccountRole.IV)
{
//super
return Enum.GetValues(typeof(EAccountRole)).Cast<EAccountRole>().Where(f => f != EAccountRole.IV);
}
else
{
//admin
return Enum.GetValues(typeof(EAccountRole)).Cast<EAccountRole>().Where(f => f != EAccountRole.IV || f != EAccountRole.III);
}
}
}

posted @ 2023-02-25 13:09  耕耘理想的农夫  阅读(64)  评论(0编辑  收藏  举报