简体   繁体   中英

C# HttpGet Enum.GetValues return liste

I want to return the "Liste" but I don't know how.

[HttpGet("GetType")]
public async Task<IActionResult> GetTemplateType()
{
    var liste = Enum.GetValues(typeof(NotificationTemplateType));
    return liste;
}

I get this error:

While commented hints are not wrong, You have here a walk through edition, using xUnit for the extended version first

public enum NotificationTemplateType
{
    Undefined = 0,
    Pigeon = 1,
    Shout = 2,
    Mail = 3,
    Team = 4,
    Skype = 5,
    Slack = 6,
    Viber = 7,
}

[Fact]
public void VerifyIsAListTest()
{
    var undefinedArray = Enum.GetValues(typeof(NotificationTemplateType));
    var specificArray = (NotificationTemplateType[])undefinedArray;
    var elementsListThoughArrayWillBeFineWhenReturningBesidesForTheController = specificArray.ToList();
    Assert.IsType<List<NotificationTemplateType>>(elementsListThoughArrayWillBeFineWhenReturningBesidesForTheController);
}

So Your method could be (please format better with linebreaks)

 [HttpGet("GetType")]
 public async Task<IActionResult> GetTemplateType()
 {
    var liste = ((NotificationTemplateType[])Enum.GetValues(typeof(NotificationTemplateType))).ToList();
    return Ok(liste);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM