62,074
社区成员
发帖
与我相关
我的任务
分享
using Common;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
namespace BWServer2017.BLL
{
[CommunicationCommand("bw.获取统计数据4")]
class Calc4 : CommandV5<ExpandoObject>
{
public override ExpandoObject Execute()
{
#if DEBUG
return Execute1();
#else
try
{
return Execute1();
}
catch (Exception ex)
{
Common.Program.WriteObjectLog("bw获取统计数据4", new
{
error = ex.ToString(),
input = this.Command.ToString()
});
throw;
}
#endif
}
private ExpandoObject Execute1()
{
var BaselienDefination = this.Command.GetValue<string>("BaselineDefination");
var DanWei = this.Command.GetValues<string>("DanWei").ToList();
if (DanWei == null || DanWei.Count == 0)
throw new Exception("DanWei参数必须有值。");
var tablename = Common.BLL.ModifyWork.GetTopTableName(BaselienDefination);
var Nian = this.Command.GetValue<int>("Nian");
var YueList = this.Command.GetValues<int>("Yue");
var FieldName = this.Command.GetValues<string>("FieldName").Where(x => !string.IsNullOrEmpty(x)).ToArray();
var r = (from y in YueList.AsParallel()
from dw in DanWei.AsParallel()
let o = BLL.Calc.Search(tablename, dw, Nian, y)
where o != null
select o).ToList();
if (r.Count == 0)
return null;
var res = r.First();
if (r.Count > 1)
{
var dic = (IDictionary<string, object>)res;
for (var i = 1; i < r.Count; i++)
{
var d = (IDictionary<string, object>)r[i];
foreach (var fld in FieldName)
dic[fld] = Convert.ToDouble(dic[fld]) + Convert.ToDouble(d[fld]);
}
}
return res;
}
}
}
反编译using Common;
using Common.BLL;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Runtime.CompilerServices;
namespace BWServer2017.BLL
{
[CommunicationCommand(new string[]
{
"bw.获取统计数据4"
})]
internal class Calc4 : CommandV5<ExpandoObject>
{
[CompilerGenerated]
[Serializable]
private sealed class <>c
{
public static readonly Calc4.<>c <>9 = new Calc4.<>c();
public static Func<string, bool> <>9__1_0;
public static Func<int, string, <>f__AnonymousType1<int, string>> <>9__1_2;
public static Func<<>f__AnonymousType2<<>f__AnonymousType1<int, string>, ExpandoObject>, bool> <>9__1_4;
public static Func<<>f__AnonymousType2<<>f__AnonymousType1<int, string>, ExpandoObject>, ExpandoObject> <>9__1_5;
internal bool <Execute1>b__1_0(string x)
{
return !string.IsNullOrEmpty(x);
}
internal <>f__AnonymousType1<int, string> <Execute1>b__1_2(int y, string dw)
{
return new
{
y,
dw
};
}
internal bool <Execute1>b__1_4(<>f__AnonymousType2<<>f__AnonymousType1<int, string>, ExpandoObject> <>h__TransparentIdentifier1)
{
return <>h__TransparentIdentifier1.o != null;
}
internal ExpandoObject <Execute1>b__1_5(<>f__AnonymousType2<<>f__AnonymousType1<int, string>, ExpandoObject> <>h__TransparentIdentifier1)
{
return <>h__TransparentIdentifier1.o;
}
}
public override ExpandoObject Execute()
{
ExpandoObject result;
try
{
result = this.Execute1();
}
catch (Exception ex)
{
Common.Program.WriteObjectLog("bw获取统计数据4", new
{
error = ex.ToString(),
input = base.Command.ToString()
});
throw;
}
return result;
}
private ExpandoObject Execute1()
{
string BaselienDefination = base.Command.GetValue("BaselineDefination");
List<string> DanWei = base.Command.GetValues("DanWei").ToList<string>();
if (DanWei == null || DanWei.Count == 0)
{
throw new Exception("DanWei参数必须有值。");
}
string tablename = ModifyWork.GetTopTableName(BaselienDefination);
int Nian = base.Command.GetValue("Nian");
IEnumerable<int> arg_BE_0 = base.Command.GetValues("Yue");
IEnumerable<string> arg_B3_0 = base.Command.GetValues("FieldName");
Func<string, bool> arg_B3_1;
if ((arg_B3_1 = Calc4.<>c.<>9__1_0) == null)
{
arg_B3_1 = (Calc4.<>c.<>9__1_0 = new Func<string, bool>(Calc4.<>c.<>9.<Execute1>b__1_0));
}
string[] FieldName = arg_B3_0.Where(arg_B3_1).ToArray<string>();
ParallelQuery<int> arg_EE_0 = arg_BE_0.AsParallel<int>();
Func<int, IEnumerable<string>> arg_EE_1 = (int y) => DanWei.AsParallel<string>();
var arg_EE_2;
if ((arg_EE_2 = Calc4.<>c.<>9__1_2) == null)
{
arg_EE_2 = (Calc4.<>c.<>9__1_2 = new Func<int, string, <>f__AnonymousType1<int, string>>(Calc4.<>c.<>9.<Execute1>b__1_2));
}
var arg_123_0 = from <>h__TransparentIdentifier0 in arg_EE_0.SelectMany(arg_EE_1, arg_EE_2)
select new
{
<>h__TransparentIdentifier0 = <>h__TransparentIdentifier0,
o = Calc.Search(tablename, <>h__TransparentIdentifier0.dw, Nian, <>h__TransparentIdentifier0.y)
};
var arg_123_1;
if ((arg_123_1 = Calc4.<>c.<>9__1_4) == null)
{
arg_123_1 = (Calc4.<>c.<>9__1_4 = new Func<<>f__AnonymousType2<<>f__AnonymousType1<int, string>, ExpandoObject>, bool>(Calc4.<>c.<>9.<Execute1>b__1_4));
}
var arg_147_0 = arg_123_0.Where(arg_123_1);
var arg_147_1;
if ((arg_147_1 = Calc4.<>c.<>9__1_5) == null)
{
arg_147_1 = (Calc4.<>c.<>9__1_5 = new Func<<>f__AnonymousType2<<>f__AnonymousType1<int, string>, ExpandoObject>, ExpandoObject>(Calc4.<>c.<>9.<Execute1>b__1_5));
}
List<ExpandoObject> r = arg_147_0.Select(arg_147_1).ToList<ExpandoObject>();
if (r.Count == 0)
{
return null;
}
ExpandoObject res = r.First<ExpandoObject>();
if (r.Count > 1)
{
IDictionary<string, object> dic = res;
for (int i = 1; i < r.Count; i++)
{
IDictionary<string, object> d = r[i];
string[] array = FieldName;
for (int j = 0; j < array.Length; j++)
{
string fld = array[j];
dic[fld] = Convert.ToDouble(dic[fld]) + Convert.ToDouble(d[fld]);
}
}
}
return res;
}
}
}
这里很显然,最后的那个 for 循环部分,原本只要简单地写一行 Foreach 委托代码就行了,而我当时按照初学者的方式写成比较多行的 fo 循环语句了,所以反编译出来的结果跟源代码比较接近。而其它部分,我就是按照业务逻辑来写,很自然地写成一个 linq 查询,你看看反编译出什么?!
这还只是抠个别语句。而真正的项目需要改造时,其实并不是在于个别语句是不是方便于“城下打洞”的问题,而是要舍得从项目考虑。