{GUID} .Method $$ ****在代码文件中。不编译!
-
10-10-2019 - |
题
我们有一个来自另一个项目的.NET组件,其中一个来自Reflector的生成文件中的一个。
现在,VS 2010 C#编译器会抛出各种编译错误$$意外。关闭牙套等
在ILDASM中,我看到了这种方法以及许多提到的方法,但是在生成的代码中,我发现其中1个编译器的方法中有1种。
如何进行编译?
解决方案
这些通常是由 static readonly
数组。您不会编译它们。反射器还显着重新创建了琐碎的代码。
我建议您获得原始的源代码。
其他提示
这些是由编译器自动生成的,我相信诸如lambda表达式对象(您不提供任何名称)之类的东西。我相信它们的名称无效,正是因为编译器希望确保与您自己的代码没有任何冲突。您只需要在重新编译之前将其重命名。
在所有情况下,我都看到它与数组初始化器有关。如果您查看所创建的类型,您会注意到编译器刚刚为您初始化的每个大小数组创建了一个不同的结构。编译器这样做是为了降低IL大小,对数组元素的速度内存分配,并将数组元素保存在一起存储在内存中和顺序中。在不深入杂草的情况下,我只提到这样做意味着任何大小的阵列初始化发生在已知且持续数量的IL指令中。我不记得从我的Ildasm挖掘出来,但我认为是4。一次分配一个指令,每个元素4个说明。
现在解决您的具体问题。一旦您意识到自己只是处理需要重命名的价值类型实例,就不错。在反射器中进行一些搜索应揭示使用编译器生成对象的实例。原始声明和初始化将完好无损。这就是您需要遵循的全局重命名该对象的重命名。选择您想要的任何名称,然后更换编译器的生成名称。我在下面放了一些其他代码,以说明这一点。对于需要初始化的字典,它也可以优化并为每个词典创建一个新实例,称为<> f_switch $ mapn,其中n再次是计数器。
您还将处理类似的胡说八道,以适用于自动化的任何属性。相同的修复。创建自己的备份字段并使用它。
[CompilerGenerated]
internal class <PrivateImplementationDetails>
{
// Fields
internal static $ArrayType$4 $$field-0; // data size: 4 bytes
internal static $ArrayType$4 $$field-1; // data size: 4 bytes
internal static $ArrayType$4 $$field-2; // data size: 4 bytes
internal static $ArrayType$4 $$field-3; // data size: 4 bytes
internal static $ArrayType$44 $$field-4; // data size: 44 bytes
internal static $ArrayType$4 $$field-5; // data size: 4 bytes
// Nested Types
[StructLayout(LayoutKind.Explicit, Size=4, Pack=1)]
private struct $ArrayType$4
{
}
[StructLayout(LayoutKind.Explicit, Size=0x2c, Pack=1)]
private struct $ArrayType$44
{
}
}
static GATWavHelper()
{
riffBytes = new byte[] { 0x52, 0x49, 70, 70 };
waveBytes = new byte[] { 0x57, 0x41, 0x56, 0x45 };
fmtBytes = new byte[] { 0x66, 0x6d, 0x74, 0x20 };
dataBytes = new byte[] { 100, 0x61, 0x74, 0x61 };
headerSize = 0x2c;
floatToInt16RescaleFactor = 0x7fff;
__canonicalHeader = new byte[] {
0x52, 0x49, 70, 70, 0, 0, 0, 0, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20,
0, 0, 0, 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 100, 0x61, 0x74, 0x61, 0, 0, 0, 0
};
}
// Fields
[CompilerGenerated]
private static Dictionary<string, int> <>f__switch$map0;
.
.
.
if (<>f__switch$map0 == null)
{
Dictionary<string, int> dictionary = new Dictionary<string, int>(3);
dictionary.Add("false", 0);
dictionary.Add("true", 1);
dictionary.Add("null", 2);
<>f__switch$map0 = dictionary;
}
if (<>f__switch$map0.TryGetValue(nextWord, out num))
{
switch (num)
.
.
.
从“视图”菜单中选择选项。
验证优化选择。由于您使用的是最新版本的VS,因此应指定为.NET 4.0或至少3.5优化以获得对Lambdas的支持。