I'm developing a .NETcore project where i use the apicontrollers to handle front-end requests and i'm manually parsing the JObject like so:
public IActionResult CreatePublicUser([FromBody]JObject body)
{
string Username = body["Username"].ToString();
}
I have Created an enum that basically allows me to use enumUser.Username.toString() instead of writing "Username" explicitly
public enum enumUserModel
{
Username,
Password
}
however apparently i have to do this way too often so i decided to create a class with constants like so:
public class UserModelConstants {
public static const Username = "Username";
public static const Password = "Password";
}
so i can instead write UserModelConstants.Username which makes the code looks better and easier to understand. Moreover, according to online articles it has better performance than enumUser.Username.toString()
but if i use the constants approach then i'll have to write another class to handle converting the constants to int for writing to database (which is basically using enum again).
so what the best way to approach this?