Reflector有个File Disasmbler插件,让Reflector可以把反编译的代码保存为文件。通过反编译代码与源程序文件的比较,可以看出两者是有区别的,甚至编译的代码完全有可能无法再通过编译生成程序文件。
两者都有些什么区别呢?
一、文件的改变
源代码中我们创建一个Form1,VS 一般会生成两个文件Form1.cs 和 Form1.Desinger.cs,如果添加资源后还会增加一个Forms.resx文件,而反编译代码则把Form1.cs与partial代码Form1.Desinger.cs两者合而为一。
关于控件的申明与
private void InitializeComponent()
protected override void Dispose(bool disposing)
可以手动拆分还原,然后又可以实现在VS中进行窗体设计操作了。
二、代码的改变
我们看这样源文件这样一段代码
public class EventingList<T>: System.Collections.Generic.IList<T>
{
public enum EventType { Deleted, Added };
......
}
在反编译生成的代码中成了这样的形式:
public class EventingList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
{
public enum EventType
{
public const EventingList<T>.EventType Added = EventingList<T>.EventType.Added;,
public const EventingList<T>.EventType Deleted = EventingList<T>.EventType.Deleted;
}
}
这是无法再通过编译的。
另反编译代码中还会添加很多非源代码的内容
[CompilerGenerated]
private sealed class <GetEnumerator>d__0 : IEnumerator<T>, IEnumerator, IDisposable
{
private int <>1__state;
private T <>2__current;
public Set<T> <>4__this;
public Dictionary<T, int>.Enumerator <>7__wrap2;
public KeyValuePair<T, int> <kvp>5__1;
[DebuggerHidden]
public <GetEnumerator>d__0(int <>1__state)
{
this.<>1__state = <>1__state;
}
private bool MoveNext()
{
bool flag;
try
{
switch (this.<>1__state)
{
case 0:
this.<>1__state = -1;
this.<>7__wrap2 = this.<>4__this._values.GetEnumerator();
this.<>1__state = 1;
goto Label_007B;
根据提示信息是编译生成的,但编译是什么情况下又是怎么产生这些内容的有待进一步研究。