我有一个枚举:-
public enum EnumType
{
Type1_Template,
Type2_Folders,
Type3_Template,
Type1_Folders,
}
现在,在我想要的控制器中
- 枚举列表和
- 将 _ 下划线替换为空格。
所以为此:-获取我拥有的枚举列表
return new Models.DTOObject()
{
ID = model.id,
Name = model.Name,
Description = model.Description,
//Type is the property where i want the List<Enum> and replace the underscore with space
Type = Enum.GetValues(typeof(EnumType)).Cast<EnumType>().ToList()
};
但是现在,我正在尝试这样的事情(虽然听起来可能很奇怪):-
return new Models.Customers()
{
ID = model.id,
Name = model.Name,
Description = model.Description,
//Type is the property where i want the List<Enum> and replace the underscore with space
Type = Enum.GetValues(typeof(EnumType)).Cast<EnumType>().ToList().Select(e => new
{
Value = e,
Text = e.ToString().Replace("_", " ")
})
};
但会引发语法错误(';' missing )。虽然它只是被试了一下。请让我知道我该如何实现它。