c# - Invalid enum value -
so have type:
public enum types { aaa= 1, bbb= 2, ccc= 4 } public class requestpayload { public int prop1 { get; set; } public string prop2 { get; set; } public types prop3 { get; set; } }
and postman testing web api.
public mytype create([frombody] requestpayloadpayload) { return null }
here postman settings:
so why in controller object has property prop3
6666 when enum not have value?
i don't know "postman", assume you're surprised int value other 1, 2, or 4 can assigned prop3
. reason - that's how enums work in c# since, under hood, field of enum type converted int
(or whatever underlying type of enum is), int
value can legally stored in it.
from msdn:
enum days : byte {sat=1, sun, mon, tue, wed, thu, fri};
a variable of type
days
can assigned value in range of underlying type; values not limited named constants.
this probably avoid expensive run-time checking of values against "defined" values, there may other architectural reasons (the use of "flag" enums 1 comes mind).
Comments
Post a Comment