日期:2014-05-20  浏览次数:20788 次

delegate 模式 如何应用




        private static void GetContractNode(Program p, XmlHelper xh, Hashtable htAt, Hashtable htValue, string xpathForContract)
        {

            ClearHt(htAt, htValue);
            htAt.Add(p.GetNameStr(), p.GetContractInformation());
            xh.InsertNode(p.xmlFileName, p.GetContractInfo(), true, p.GetReportInfo(), htAt, htValue);


            ClearHt(htAt, htValue);
            htAt.Add(p.GetNameStr(), p.GetContractNumber());
            htAt.Add(p.GetTypeStr(), p.GetStringStr());
            htAt.Add(p.GetValueStr(), "9");
            xh.InsertNode(p.xmlFileName, p.GetParameterStr(), true, xpathForContract, htAt, htValue);

            ClearHt(htAt, htValue);
            htAt.Add(p.GetNameStr(), p.GetOrderType());
            htAt.Add(p.GetTypeStr(), p.GetStringStr());
            htAt.Add(p.GetValueStr(), "压力订单");
            xh.InsertNode(p.xmlFileName, p.GetParameterStr(), true, xpathForContract, htAt, htValue);
//比如 我下面 还有1000行 与上面相同的代码 只是 htAt添加的内容不同
  }
    

//还有个方法 也类似

private static void GetCustomerNode(Program p, XmlHelper xh, Hashtable htAt, Hashtable htValue, string xpathForCustomer)
        {
            ClearHt(htAt, htValue);
            htAt.Add(p.GetNameStr(), p.GetCustomerInformation());
            xh.InsertNode(p.xmlFileName, p.GetCustomerInfo(), true, p.GetReportInfo(), htAt, htValue);

            ClearHt(htAt, htValue);
            htAt.Add(p.GetNameStr(), p.GetCustomerName());
            htAt.Add(p.GetTypeStr(), p.GetStringStr());
            htAt.Add(p.GetValueStr(), "压力哥");
            xh.InsertNode(p.xmlFileName, p.GetParameterStr(), true, xpathForCustomer, htAt, htValue);
//比如 我下面 还有1000行 与上面相同的代码 只是 htAt添加的内容不同
 
        }



这2个方法 看起来结构类似 传递的参数 内容不一样 ,还有方法内部的实现 好多看起来重复的。。我要怎么重构模式呢。。 我想不出好的办法, 请高手指点

------解决方案--------------------