Is is possible to dynamically deserialize my enum string into enums.
In my API and my application that consumes my API i have this class.
public static class ErrorCodes
{
public enum General
{
INCORRECT_PASSWORD,
INCORRECT_USERNAME,
INVALID_USERNAME
}
public enum ERRORTYPE_1
{
DATESPAN_NOT_PERMITTED
}
public enum ERRORTYPE_2
{
PERIOD_NOT_ALLOWED
}
}
In my API i have this. This is what is send back to my application in JSON form.
public class Error
{
public string Message { get; set; }
public Enum Code { get; set; }
public Error() { }
public Error(Enum code)
{
this.Code = code;
}
public Error(string message, Enum code)
{
this.Message = message;
this.Code = code;
}
}
I can then return my error like this.
new Error(ErrorCodes.ERRORTYPE_2.PERIOD_NOT_ALLOWED)
Is there a way to keep my enums seperate? I feel like a super long list of enum error codes is not very clean or maintainable.
This blog post is pretty much what i want to do but with more abstraction of enums. https://bytefish.de/blog/enums_json_net/