【发布时间】:2021-04-09 07:36:34
【问题描述】:
我有一个数据实体,其属性“UserType”作为枚举返回,需要将其转换为另一个。
第一个枚举是(数字基于数据库中的值):
public enum UserType
{
Primary = 100001,
Secondary = 100002,
Other = 100003
}
这就是我想将其转换为:
public enum UserType
{
Primary,
Secondary,
Other
}
这是为了在这个类上设置 UserType:
public class UserData
{
public UserType UserType{ get; set; }
}
可能是以下内容?
MemberType = MemberType(entity.MemberType.ReadValue())
请问有人知道最好的方法吗?
【问题讨论】:
-
首选项:创建一个接受
OldUserType并返回NewUserType的映射。做不到这一点,也许Enum.Parse<NewUserType>(OldUserType.Primary.ToString());? -
这能回答你的问题吗? convert an enum to another type of enum
标签: c#