1.有静态构造函数的cs文件
有静态构造函数的cs源文件
namespace ConsoleAppBasic
{
internal class HasStaticCtorClass
{
static int x;
int y;
static int Z;
int D;
internal static int X
{
get
{
return x;
}
set
{
x = value;
}
}
internal int Y
{
get
{
return y;
}
set
{
y= value;
}
}
static HasStaticCtorClass() { }
internal HasStaticCtorClass() { }
}
}
2.无静态构造函数的cs文件
无静态构造函数的cs文件
namespace ConsoleAppBasic
{
internal class NoStaticCtorClass
{
static int x;
int y;
static int Z;
int D;
internal static int X
{
get
{
return x;
}
set
{
x = value;
}
}
internal int Y
{
get
{
return y;
}
set
{
y = value;
}
}
internal NoStaticCtorClass() { }
}
}
3.有静态构造函数的反编译C#代码
有静态构造函数的反编译C#代码
using System;
namespace ConsoleAppBasic
{
// Token: 0x02000005 RID: 5
internal class HasStaticCtorClass
{
// Token: 0x17000001 RID: 1
// (get) Token: 0x0600000A RID: 10 RVA: 0x000024A8 File Offset: 0x000006A8
// (set) Token: 0x0600000B RID: 11 RVA: 0x000024BF File Offset: 0x000006BF
internal static int X
{
get
{
return HasStaticCtorClass.x;
}
set
{
HasStaticCtorClass.x = value;
}
}
// Token: 0x17000002 RID: 2
// (get) Token: 0x0600000C RID: 12 RVA: 0x000024C8 File Offset: 0x000006C8
// (set) Token: 0x0600000D RID: 13 RVA: 0x000024E0 File Offset: 0x000006E0
internal int Y
{
get
{
return this.y;
}
set
{
this.y = value;
}
}
// Token: 0x0600000F RID: 15 RVA: 0x000024ED File Offset: 0x000006ED
internal HasStaticCtorClass()
{
}
// Token: 0x04000002 RID: 2
private static int x;
// Token: 0x04000003 RID: 3
private int y;
// Token: 0x04000004 RID: 4
private static int Z;
// Token: 0x04000005 RID: 5
private int D;
}
}
4.无静态构造函数的反编译C#代码
无静态构造函数的反编译C#代码
using System;
namespace ConsoleAppBasic
{
// Token: 0x02000006 RID: 6
internal class NoStaticCtorClass
{
// Token: 0x17000003 RID: 3
// (get) Token: 0x06000010 RID: 16 RVA: 0x000024F8 File Offset: 0x000006F8
// (set) Token: 0x06000011 RID: 17 RVA: 0x0000250F File Offset: 0x0000070F
internal static int X
{
get
{
return NoStaticCtorClass.x;
}
set
{
NoStaticCtorClass.x = value;
}
}
// Token: 0x17000004 RID: 4
// (get) Token: 0x06000012 RID: 18 RVA: 0x00002518 File Offset: 0x00000718
// (set) Token: 0x06000013 RID: 19 RVA: 0x00002530 File Offset: 0x00000730
internal int Y
{
get
{
return this.y;
}
set
{
this.y = value;
}
}
// Token: 0x06000014 RID: 20 RVA: 0x0000253A File Offset: 0x0000073A
internal NoStaticCtorClass()
{
}
// Token: 0x04000006 RID: 6
private static int x;
// Token: 0x04000007 RID: 7
private int y;
// Token: 0x04000008 RID: 8
private static int Z;
// Token: 0x04000009 RID: 9
private int D;
}
}
5.有静态构造函数的反编译IL代码
有静态构造函数的反编译IL代码
// Token: 0x02000005 RID: 5
.class private auto ansi ConsoleAppBasic.HasStaticCtorClass
extends [System.Runtime]System.Object
{
// Fields
// Token: 0x04000002 RID: 2
.field private static int32 x
// Token: 0x04000003 RID: 3
.field private int32 y
// Token: 0x04000004 RID: 4
.field private static int32 Z
// Token: 0x04000005 RID: 5
.field private int32 D
// Methods
// Token: 0x0600000A RID: 10 RVA: 0x000024A8 File Offset: 0x000006A8
.method assembly hidebysig specialname static
int32 get_X () cil managed
{
// Header Size: 12 bytes
// Code Size: 11 (0xB) bytes
// LocalVarSig Token: 0x11000007 RID: 7
.maxstack 1
.locals init (
[0] int32
)
/* (13,13)-(13,14) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006B4 00 */ IL_0000: nop
/* (14,17)-(14,26) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006B5 7E02000004 */ IL_0001: ldsfld int32 ConsoleAppBasic.HasStaticCtorClass::x
/* 0x000006BA 0A */ IL_0006: stloc.0
/* 0x000006BB 2B00 */ IL_0007: br.s IL_0009
/* (15,13)-(15,14) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006BD 06 */ IL_0009: ldloc.0
/* 0x000006BE 2A */ IL_000A: ret
} // end of method HasStaticCtorClass::get_X
// Token: 0x0600000B RID: 11 RVA: 0x000024BF File Offset: 0x000006BF
.method assembly hidebysig specialname static
void set_X (
int32 'value'
) cil managed
{
// Header Size: 1 byte
// Code Size: 8 (0x8) bytes
.maxstack 8
/* (17,13)-(17,14) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006C0 00 */ IL_0000: nop
/* (18,17)-(18,27) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006C1 02 */ IL_0001: ldarg.0
/* 0x000006C2 8002000004 */ IL_0002: stsfld int32 ConsoleAppBasic.HasStaticCtorClass::x
/* (19,13)-(19,14) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006C7 2A */ IL_0007: ret
} // end of method HasStaticCtorClass::set_X
// Token: 0x0600000C RID: 12 RVA: 0x000024C8 File Offset: 0x000006C8
.method assembly hidebysig specialname
instance int32 get_Y () cil managed
{
// Header Size: 12 bytes
// Code Size: 12 (0xC) bytes
// LocalVarSig Token: 0x11000007 RID: 7
.maxstack 1
.locals init (
[0] int32
)
/* (24,13)-(24,14) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006D4 00 */ IL_0000: nop
/* (25,17)-(25,26) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006D5 02 */ IL_0001: ldarg.0
/* 0x000006D6 7B03000004 */ IL_0002: ldfld int32 ConsoleAppBasic.HasStaticCtorClass::y
/* 0x000006DB 0A */ IL_0007: stloc.0
/* 0x000006DC 2B00 */ IL_0008: br.s IL_000A
/* (26,13)-(26,14) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006DE 06 */ IL_000A: ldloc.0
/* 0x000006DF 2A */ IL_000B: ret
} // end of method HasStaticCtorClass::get_Y
// Token: 0x0600000D RID: 13 RVA: 0x000024E0 File Offset: 0x000006E0
.method assembly hidebysig specialname
instance void set_Y (
int32 'value'
) cil managed
{
// Header Size: 1 byte
// Code Size: 9 (0x9) bytes
.maxstack 8
/* (28,13)-(28,14) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006E1 00 */ IL_0000: nop
/* (29,17)-(29,26) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006E2 02 */ IL_0001: ldarg.0
/* 0x000006E3 03 */ IL_0002: ldarg.1
/* 0x000006E4 7D03000004 */ IL_0003: stfld int32 ConsoleAppBasic.HasStaticCtorClass::y
/* (30,13)-(30,14) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006E9 2A */ IL_0008: ret
} // end of method HasStaticCtorClass::set_Y
// Token: 0x0600000E RID: 14 RVA: 0x000024EA File Offset: 0x000006EA
.method private hidebysig specialname rtspecialname static
void .cctor () cil managed
{
// Header Size: 1 byte
// Code Size: 2 (0x2) bytes
.maxstack 8
/* (33,37)-(33,38) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006EB 00 */ IL_0000: nop
/* (33,39)-(33,40) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006EC 2A */ IL_0001: ret
} // end of method HasStaticCtorClass::.cctor
// Token: 0x0600000F RID: 15 RVA: 0x000024ED File Offset: 0x000006ED
.method assembly hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Header Size: 1 byte
// Code Size: 9 (0x9) bytes
.maxstack 8
/* (35,9)-(35,38) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006EE 02 */ IL_0000: ldarg.0
/* 0x000006EF 282A00000A */ IL_0001: call instance void [System.Runtime]System.Object::.ctor()
/* 0x000006F4 00 */ IL_0006: nop
/* (35,39)-(35,40) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006F5 00 */ IL_0007: nop
/* (35,41)-(35,42) ~\ConsoleAppFramework\ConsoleAppBasic\HasStaticCtorClass.cs */
/* 0x000006F6 2A */ IL_0008: ret
} // end of method HasStaticCtorClass::.ctor
// Properties
// Token: 0x17000001 RID: 1
.property int32 X()
{
// Token: 0x0600000A RID: 10 RVA: 0x000024A8 File Offset: 0x000006A8
.get int32 ConsoleAppBasic.HasStaticCtorClass::get_X()
// Token: 0x0600000B RID: 11 RVA: 0x000024BF File Offset: 0x000006BF
.set void ConsoleAppBasic.HasStaticCtorClass::set_X(int32)
}
// Token: 0x17000002 RID: 2
.property instance int32 Y()
{
// Token: 0x0600000C RID: 12 RVA: 0x000024C8 File Offset: 0x000006C8
.get instance int32 ConsoleAppBasic.HasStaticCtorClass::get_Y()
// Token: 0x0600000D RID: 13 RVA: 0x000024E0 File Offset: 0x000006E0
.set instance void ConsoleAppBasic.HasStaticCtorClass::set_Y(int32)
}
} // end of class ConsoleAppBasic.HasStaticCtorClass
6.无静态构造函数的反编译IL代码
无静态构造函数的反编译IL代码
// Token: 0x02000006 RID: 6
.class private auto ansi beforefieldinit ConsoleAppBasic.NoStaticCtorClass
extends[System.Runtime]System.Object
{
// Fields
// Token: 0x04000006 RID: 6
.field private static int32 x
// Token: 0x04000007 RID: 7
.field private int32 y
// Token: 0x04000008 RID: 8
.field private static int32 Z
// Token: 0x04000009 RID: 9
.field private int32 D
// Methods
// Token: 0x06000010 RID: 16 RVA: 0x000024F8 File Offset: 0x000006F8
.method assembly hidebysig specialname static
int32 get_X() cil managed
{
// Header Size: 12 bytes
// Code Size: 11 (0xB) bytes
// LocalVarSig Token: 0x11000007 RID: 7
.maxstack 1
.locals init (
[0] int32
)
/* (13,13)-(13,14) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000704 00 */ IL_0000: nop
/* (14,17)-(14,26) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000705 7E06000004 */ IL_0001: ldsfld int32 ConsoleAppBasic.NoStaticCtorClass::x
/* 0x0000070A 0A */ IL_0006: stloc.0
/* 0x0000070B 2B00 */ IL_0007: br.s IL_0009
/* (15,13)-(15,14) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x0000070D 06 */ IL_0009: ldloc.0
/* 0x0000070E 2A */ IL_000A: ret
} // end of method NoStaticCtorClass::get_X
// Token: 0x06000011 RID: 17 RVA: 0x0000250F File Offset: 0x0000070F
.method assembly hidebysig specialname static
void set_X(
int32 'value'
) cil managed
{
// Header Size: 1 byte
// Code Size: 8 (0x8) bytes
.maxstack 8
/* (17,13)-(17,14) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000710 00 */ IL_0000: nop
/* (18,17)-(18,27) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000711 02 */ IL_0001: ldarg.0
/* 0x00000712 8006000004 */ IL_0002: stsfld int32 ConsoleAppBasic.NoStaticCtorClass::x
/* (19,13)-(19,14) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000717 2A */ IL_0007: ret
} // end of method NoStaticCtorClass::set_X
// Token: 0x06000012 RID: 18 RVA: 0x00002518 File Offset: 0x00000718
.method assembly hidebysig specialname
instance int32 get_Y () cil managed
{
// Header Size: 12 bytes
// Code Size: 12 (0xC) bytes
// LocalVarSig Token: 0x11000007 RID: 7
.maxstack 1
.locals init (
[0] int32
)
/* (24,13)-(24,14) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000724 00 */ IL_0000: nop
/* (25,17)-(25,26) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000725 02 */ IL_0001: ldarg.0
/* 0x00000726 7B07000004 */ IL_0002: ldfld int32 ConsoleAppBasic.NoStaticCtorClass::y
/* 0x0000072B 0A */ IL_0007: stloc.0
/* 0x0000072C 2B00 */ IL_0008: br.s IL_000A
/* (26,13)-(26,14) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x0000072E 06 */ IL_000A: ldloc.0
/* 0x0000072F 2A */ IL_000B: ret
} // end of method NoStaticCtorClass::get_Y
// Token: 0x06000013 RID: 19 RVA: 0x00002530 File Offset: 0x00000730
.method assembly hidebysig specialname
instance void set_Y (
int32 'value'
) cil managed
{
// Header Size: 1 byte
// Code Size: 9 (0x9) bytes
.maxstack 8
/* (28,13)-(28,14) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000731 00 */ IL_0000: nop
/* (29,17)-(29,27) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000732 02 */ IL_0001: ldarg.0
/* 0x00000733 03 */ IL_0002: ldarg.1
/* 0x00000734 7D07000004 */ IL_0003: stfld int32 ConsoleAppBasic.NoStaticCtorClass::y
/* (30,13)-(30,14) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000739 2A */ IL_0008: ret
} // end of method NoStaticCtorClass::set_Y
// Token: 0x06000014 RID: 20 RVA: 0x0000253A File Offset: 0x0000073A
.method assembly hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Header Size: 1 byte
// Code Size: 9 (0x9) bytes
.maxstack 8
/* (33,9)-(33,37) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x0000073B 02 */ IL_0000: ldarg.0
/* 0x0000073C 282A00000A */ IL_0001: call instance void [System.Runtime]System.Object::.ctor()
/* 0x00000741 00 */ IL_0006: nop
/* (33,38)-(33,39) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000742 00 */ IL_0007: nop
/* (33,40)-(33,41) ~\ConsoleAppFramework\ConsoleAppBasic\NoStaticCtorClass.cs */
/* 0x00000743 2A */ IL_0008: ret
} // end of method NoStaticCtorClass::.ctor
// Properties
// Token: 0x17000003 RID: 3
.property int32 X()
{
// Token: 0x06000010 RID: 16 RVA: 0x000024F8 File Offset: 0x000006F8
.get int32 ConsoleAppBasic.NoStaticCtorClass::get_X()
// Token: 0x06000011 RID: 17 RVA: 0x0000250F File Offset: 0x0000070F
.set void ConsoleAppBasic.NoStaticCtorClass::set_X(int32)
}
// Token: 0x17000004 RID: 4
.property instance int32 Y()
{
// Token: 0x06000012 RID: 18 RVA: 0x00002518 File Offset: 0x00000718
.get instance int32 ConsoleAppBasic.NoStaticCtorClass::get_Y()
// Token: 0x06000013 RID: 19 RVA: 0x00002530 File Offset: 0x00000730
.set instance void ConsoleAppBasic.NoStaticCtorClass::set_Y(int32)
}
} // end of class ConsoleAppBasic.NoStaticCtorClass
7.对比分析
IL分析
- 类类型后默认添加内容extends [System.Runtime]System.Object,针对Struct类型添加内容extends [System.Runtime]System.ValueType,针对枚举类型添加内容extends [System.Runtime]System.Enum
- 在IL中出现了“(13,13)-(13,14)”“(14,17)-(14,26)”,这里表示实际的cs类文件中的位置信息,在vs的编辑页面右下角可以查看到
- 属性都有了自己的get、set方法
- 如果没有显示指定get、set方法中的字段,例如{get;set;},则会添加默认的字段信息
- 对于属性的set方法,会默认传入对应的数据类型以及'value'信息
- 在IL代码中,增加了一些标记信息,如“// Fields”、“// Methods”、“// Properties”
- 非静态(static)属性、方法添加了instance标记