I have the following class and enum:
public class Email
{
string Address;
EEmailType Type;
}
public enum EEmailType
{
Primary,
Alternative
}
The problem I'm seeing is that I have a handler where I return a collection of these objects as a json response.
The response is coming fine and includes the email address for all the emails I can fetch, but the email type is not returned.
When I get the response I instead get :
[
{
address : "Joe@gmail.com"
}
]
So the type of email is nowhere to be seen. Also, in the mapper where I'm building this collection I call a function that converts a string we receive from the backend to an enum:
public EEmailType convertToEnum(string input)
{
switch(input)
{
case "Primary" :
return EEmailType.Primary;
......... *and so on*
}
}
But if instead of using my function I directly hardcode a value then it does show up in the json string which is returned:
emails.Add(
new Email {
Address : response.address,
Type : convertToEnum(response.type) <----- THIS DOES NOT WORK
});
emails.Add(
new Email {
Address : response.address,
Type : EEmailType.Primary <----- THIS WORKS FINE
});
What am I doing wrong here?