Replace switch statement

给你一囗甜甜゛ 提交于 2020-11-30 02:09:27

问题


I have to calculate the price based on multiple input variables

public class Model
{
    public int Account { get; set; }
    public long Related{ get; set; }
    public int TransactionType { get; set; }
    public string detail{ get; set; }
    public int PlanId { get; set; }      
}

First switch starts with TransactionType . Based on TransactionType I need to use Account,PlanId ,Related fields for more information from database to get more information and some configurable information. There are more conditions based on those database values. Of coarse there are some common logic and information required between different TransactionType

now i can use

switch (TransactionType)
{
   case 1:
     //Check Related value and get more information from database
     //Apply buisness rule
     //Check PlanId value and get more information from database
     //Apply buisness rule
     //Get final value
     break;
   case 2
     //Check Related value and get more information from database
     //Apply buisness rule
     //Check PlanId value and get more information from database
     //Apply buisness rule
     //Get final value
     break;
   default:
     break;
}

Please help me how i can avoid these switch statements

来源:https://stackoverflow.com/questions/64775946/replace-switch-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!