如何将枚举转换为列表并将'_'替换为''(空格)

Shu*_*ubh 0 c# enums

我有一个枚举: -

    public enum EnumType
    {
        Type1_Template,
        Type2_Folders,
        Type3_Template,
        Type1_Folders,
    }
Run Code Online (Sandbox Code Playgroud)

现在,在我想要的控制器中

  1. Enum和
  2. 用空格替换_下划线.

所以为此: - 获得Enum列表

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()
            };
Run Code Online (Sandbox Code Playgroud)

但是现在,我正在尝试这样的事情(听起来可能很奇怪): -

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("_", " ")
                })
            };
Run Code Online (Sandbox Code Playgroud)

但抛出语法错误(';'缺失).虽然它只是尝试了一些东西.请让我知道如何实现它.

dut*_*tzu 8

你应该能做到的

Enum.GetNames(typeof(EnumType)).Select(item => item.Replace('_',' '));
Run Code Online (Sandbox Code Playgroud)