首页 > 解决方案 > CIL:当分配给“.field”时,“class”关键字是什么意思?

问题描述

我有一个字段定义:

.field public static initonly class A.Program/'<>c' '<>9'

这是 C# 编译器生成的嵌套类型的一部分。我想使用 ILGenerator.Emit 构建类似的东西。

使用 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#)

标签: c#.netcil

解决方案



推荐阅读