Dynamic switch cases

后端 未结 4 693
孤独总比滥情好
孤独总比滥情好 2021-01-07 04:08

I\'m trying to make a simple switch case console menu for a few different users: admin, moderator, and user. admin would

4条回答
  •  伪装坚强ぢ
    2021-01-07 04:23

    Switch (no pun intended) it around do check for role at each case. And then if it is not allowed to do it, skip it.

    string i = Console.ReadLine();
    if (allowed(userType, i)){
      switch(i):
      case "create": Console.WriteLine("Created");
          handleCreate();
      break;
      case "show":Console.WriteLine("Showed");
          handleShow();
      break;
      case "delete":Console.WriteLine("Deleted");
          handleDelete();
      break;
      default: Console.WriteLine("Default");
        handleDefault(userType);
      break;
    }
    

提交回复
热议问题