我试图使用Reg Gate的Reflector从程序集中恢复源代码.原始资源利用了几个C#3.0功能,这使得恢复有点困难.例如,这里是匿名类型的恢复源.弹出的第一件事是在from上的类标识符.运行时类型命
[DebuggerDisplay(@"\{ OverrideType = {OverrideType}, EntityType = {EntityType} }", Type="<Anonymous Type>"), CompilerGenerated] internal sealed class <>f__AnonymousType1<<OverrideType>j__TPar, <EntityType>j__TPar> { [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly <EntityType>j__TPar <EntityType>i__Field; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly <OverrideType>j__TPar <OverrideType>i__Field; [DebuggerHidden] public <>f__AnonymousType1(<OverrideType>j__TPar OverrideType, <EntityType>j__TPar EntityType) { this.<OverrideType>i__Field = OverrideType; this.<EntityType>i__Field = EntityType; } [DebuggerHidden] public override bool Equals(object value) { var type = value as <>f__AnonymousType1<<OverrideType>j__TPar, <EntityType>j__TPar>; return (((type != null) && EqualityComparer<> <<OverrideType>j__TPar>.Default.Equals(this.<OverrideType>i__Field, type.<OverrideType>i__Field)) && EqualityComparer<<EntityType>j__TPar>.Default.Equals(this.<EntityType>i__Field, type.<EntityType>i__Field)); } [DebuggerHidden] public override int GetHashCode() { int num = -338316509; num = (-1521134295 * num) + EqualityComparer<<OverrideType>j__TPar>.Default.GetHashCode(this.<OverrideType>i__Field); return ((-1521134295 * num) + EqualityComparer<<EntityType>j__TPar>.Default.GetHashCode(this.<EntityType>i__Field)); } [DebuggerHidden] public override string ToString() { StringBuilder builder = new StringBuilder(); builder.Append("{ OverrideType = "); builder.Append(this.<OverrideType>i__Field); builder.Append(", EntityType = "); builder.Append(this.<EntityType>i__Field); builder.Append(" }"); return builder.ToString(); } public <EntityType>j__TPar EntityType { get { return this.<EntityType>i__Field; } } public <OverrideType>j__TPar OverrideType { get { return this.<OverrideType>i__Field; } } }该术语通常用于名称为<>在它们中是无法形容的名字 – 因为它们不是有效的C#.这可以防止它们与非编译器生成的名称冲突,并阻止您尝试在C#中引用它们.
可能导致它们的一些事情:
>迭代器块生成嵌套类型以实现它们.
>数组初始值设定项,例如:
int[] x = new int[] { 1, 2, 3 };
将生成< PrivateImplementationDetails> {…}类. (但仅适用于某些类型.)
> Lambda表达式可以创建新方法和新类型来实现逻辑,静态变量用于在可能的情况下缓存委托和表达式树
>如果在打开调试信息的情况下编译,则集合和对象初始值设定项如下:
List<string> list = new List<string> { "hello", "there" }`) Button button = new Button { Text = "Hi" };
将导致生成具有不可描述名称的局部变量. (在分配属性和实际变量分配之前,它们用于保存临时值,同时分配属性和添加项目.)
> C#4中的动态代码可以创建各种奇怪而美妙的东西
如果你在Reflector(View / Options / Disassembler)中打开“优化”级别,它通常会尽力给你一些类似原始源代码的东西 – 关闭优化以获得有趣的体验:)