我偶然发现了这个
question
询问linq的聚合算法,并认为这是逆向工程最能回答的问题,所以我去了Visual Studio并编写了以下代码(此代码用于Compact框架项目,其中Combine函数只能有两个参数):
public static string Combine(string path1, params string[] paths)
{
return paths.Aggregate(path1, System.IO.Path.Combine);
}
然后,我将光标设置为Aggregate方法,按F12键(我安装了Resharper),并得到以下代码:
// Decompiled with JetBrains decompiler
// Type: System.Linq.Enumerable
// Assembly: System.Core, Version=3.9.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac, Retargetable=Yes
// MVID: 77D23A6E-E19D-435B-9CBB-733D74F92072
// Assembly location: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsEmbeddedCompact\v3.9\System.Core.dll
Lots of stuff...
public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func)
{
// Stub method ('ret' instruction only)
}
很明显,这不是我调用Aggregate时运行的代码,因为…Aggregation做了一些事情。问题是,反编译器的结果究竟意味着什么?什么是对“聚合”方法进行逆向工程的合适方法?
--编辑--
我刚刚意识到我上面所说的只有在
紧凑型框架
当我反编译标准框架的Aggregate时,我得到了正确的源代码。