这两天,可把本人愁坏了。固态硬盘坏了,给客户修修补补了两个多月的C#WinForm软件,由于疏忽大意,没有备份,整个白天干了!怎么办,反编译吧。于是从客户处把编译后EXE、DLL文件拿回来,一番折腾,还真的反编译过来了,但是要想整体使用,不太现实,但是编写的代码还是可以复制、粘贴过来的。一个意外的收获是:反编译过来的代码比我原来的代码有些地方要简洁的多。看来,对于自己编写的代码精练与否,以后还得多用反编译工具。下面发两段代码供大家分析:
原来的代码:
//如果已有的计量单位表中无本次输入计量单位的名称,则添加
string sql = "select * from Unit where Name = '" + product.DW + "'";
DataTable dtUnit = SqlHelp.Database.ExecSqlReturnDataTable(sql);
if (dtUnit.Rows.Count == 0)
{
Unit unit = new Unit();
unit.Id = DataAccess.Unit.getUnitID();
unit.Name = product.DW;
unit.UnitAdd();
}
用Reflector反编译后的代码:
if (Database.ExecSqlReturnDataTable("select * from Unit where Name = '" + product.DW + "'").Rows.Count == 0)
{
new DataAccess.Unit { Id = DataAccess.Unit.getUnitID(), Name = product.DW }.UnitAdd();
}
原来的代码:
//如果已有的品种表中无本次输入的品种名称,则添加
if (product.ChanDi != "")
{
string sql1 = "select * from PinZhong where Name = '" + product.ChanDi + "'";
DataTable dtPinZhong = SqlHelp.Database.ExecSqlReturnDataTable(sql1);
if (dtPinZhong.Rows.Count == 0)
{
PinZhong pinzhong = new PinZhong();
pinzhong.Id = DataAccess.PinZhong.getPinZhongID();
pinzhong.Name = product.ChanDi;
pinzhong.PinZhongAdd();
}
}
用Reflector反编译后的代码:
if ((product.ChanDi != "") && (Database.ExecSqlReturnDataTable("select * from PinZhong where Name = '" + product.ChanDi + "'").Rows.Count == 0))
{
new PinZhong { Id = PinZhong.getPinZhongID(), Name = product.ChanDi }.PinZhongAdd();
}