c# - CIL:当分配给“.field”时,“class”关键字是什么意思?
问题描述
我有一个字段定义:
.field public static initonly class A.Program/'<>c' '<>9'
这是 C# 编译器生成的嵌套类型的一部分。我想使用 ILGenerator.Emit 构建类似的东西。
- 我试图在 ILSpy 中查看 C#,但它为我隐藏了嵌套类型(“嵌套类型”)。
- 我在ECMA-335中没有找到任何东西。
使用 ILDasm/ILasm,我构建了以下代码,希望它能给我 C#:
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly Test
{
// --- The following custom attribute is added automatically, do not uncomment -------
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 03 01 00 00 00 00 )
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module Test
// MVID: {9110E73E-F37F-4E22-9D43-20F26D4A4C8F}
// --- The following custom attribute is added automatically, do not uncomment -------
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 03 01 00 00 00 00 )
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x0000029D41150000
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi Test
extends [mscorlib]System.Object
{
.field public static initonly class System.Object 'x'
} // end of class Test
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
和
ilasm /dll /debug test.il
ILSpy 将我的.field public static initonly class System.Object 'x'
行翻译为.field public static initonly object x
(省略class
关键字并生成public static readonly object x;
C#)
解决方案
推荐阅读
- android - YouTube 缩略图不会在 webview 中加载
- docker - 为什么删除docker镜像后基于docker镜像的容器还能运行?
- powershell - powershell 从延迟链接下载文件
- node.js - 如何使用nodejs连接vpn
- c# - 如何验证返回模拟的函数工厂的调用?
- node.js - Joi:验证日期是否大于从现在开始的 x 天
- c++ - 当我指定 T 必须基于 C++ 中的某个类时,如何调用泛型变量的方法?
- wordpress - woocommerce结帐页面不断加载
- django - 如何在使用 django 按下 html 按钮时将布尔值保存到数据库中
- anova - welch-anova 之后的事后检验