首页 新闻 会员 周边 捐助

c#反射解决 switch的重复问题

0
悬赏园豆:20 [已解决问题] 解决于 2012-08-09 10:08
  public void Wc_VehicleController(string Action, FormCollection fc)
        {
            switch (Action)
            {
                case "ok_One":
                   {
                        un.model.ObjectID = Convert.ToInt16(fc["O_id"]);
                        un.model.Pversion = fc["O_name"];
                        un.model.Pversion = fc["O_Ilm"];
                        //少一个droplist
                        un.model.Pversion = fc["O_Channel"];
                        un.model.Pversion = fc["O_Model"];
                        un.model.Pversion = fc["O_id"];
                        un.model.Pversion = fc["O_Brand"];
                        un.model.Pversion = fc["O_Company"];
                        un.model.Pversion = fc["O_Color"];
                        un.model.Pversion = fc["O_Mobile2"];
                        un.model.Pversion = fc["O_name2"];
                        un.model.Pversion = fc["0_Phone"];
                        un.model.Pversion = fc["0_Time"];
                        //少一个droplist
                        un.model.Pversion = fc["O_Ratio"];
                        break;
                    }
                case "ok_two":
                    {
                        un.model.Pversion = fc["sp_offices"];
                        un.model.Pversion = fc["sp_No"];
                        un.model.Pversion = fc["sp_type"];
                        un.model.Pversion = fc["sp_chargers"];
                        un.model.Pversion = fc["sp_Ino"];
                        un.model.Pversion = fc["sp_Time"];
                        break;
                    }
                case "ok_Third":
                    {
                        un.model.ObjectID = Convert.ToInt16(fc["T_id"]);
                        un.model.Pversion = fc["un.categories"];
                        un.model.EqManufacturers = fc["T_types"];
                        un.model.Eqtypes = fc["T_version"];
                        bool flg = base.CustomerInfo.InsertModel(un.model);
                        if (flg)
                        {
                            Response.Redirect("/WC_Index/Index");
                        }
                        break;
                    }
                case "ok_Four":
                    {
                        un.model.Pversion = fc["F_No"];
                        un.model.Pversion = fc["F_contacts"];
                        un.model.Pversion = fc["F_name"];
                        un.model.Pversion = fc["E_phone"];
                        un.model.Pversion = fc["F_Pone"];
                        un.model.Pversion = fc["F_model"];
                        un.model.Pversion = fc["D_modle"];
                        un.model.Pversion = fc["F_contacts2"];
                        un.model.Pversion = fc["F_sex"];
                        un.model.Pversion = fc["F_phone2"];
                        un.model.Pversion = fc["F_model2"];
                        un.model.Pversion = fc["F_no"];
                        break;
                    }
            }
        }

这样的代码估计还多人都用过 怎么样利用反射来优化呢?

调用:

        public ActionResult InsertVehicle(string Action, FormCollection fc)
        {
           Wc_VehicleController( Action, fc);
            return View();
        }

KyrieYang的主页 KyrieYang | 菜鸟二级 | 园豆:205
提问于:2012-08-02 15:53
< >
分享
最佳答案
0
收获园豆:10
2012 | 高人七级 |园豆:21645 | 2012-08-02 16:11

我看看 谢了

KyrieYang | 园豆:205 (菜鸟二级) | 2012-08-09 10:06
其他回答(1)
0

先定义个类 把所有要操作的方法定义  然后利用type ?好像打错了那个属性就可以了 大话设计里面有

收获园豆:10
s_p | 园豆:140 (初学一级) | 2012-08-09 10:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册