У меня есть определение поля:
.field public static initonly class A.Program/'<>c' '<>9'
Это часть вложенного типа, сгенерированного компилятором C #.Я хотел бы построить нечто подобное, используя ILGenerator.Emit.
- Я пытался просмотреть C # в ILSpy, но он скрывает для меня вложенный тип («Вложенные типы»).
- Я не нашел ничего в 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 #)