Home > Enterprise >  C# HttpGet Enum.GetValues return liste
C# HttpGet Enum.GetValues return liste

Time:10-21

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:

CodePudding user response:

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);
 }
  •  Tags:  
  • c#
  • Related