Suppose you send a class-instance to controller and the class has a property of Enum type.
public class CoffeeController : ApiController
{
[HttpPost]
public async Task<IHttpActionResult> OrderAsync(Order request)
{
return Ok();
}
}
public enum CoffeeType
{
Latte,
Mocha,
Espresso
}
public class Order
{
public CoffeeType Type { get; set; }
public string Name { get; set; }
}
If there is an error in the name of enum member in request the application doesn't throw exception. It uses a default enum value instead:
{"name":"Dan", 'type':"ocha"}=>{"Name":"Dan", "Type":"Latte"}
This seems odd to me. Why such a behaviour is used?
Is there an elegant way to throw error?