msil 笔记
public class TestImpl : ITest
{// Propertiespublic string Address{get{return "abc";}}//msil:address不是在接口中定義的
//hidebysig:使用時看不見這個方法,因為是給屬性用的.specialname也是說是給屬性用的(但不指明),只是說是特殊的.
.method public hidebysig specialname instance string get_Address() cil managed
{.maxstack 1.locals init ([0] string str)L_0000: nop L_0001: ldstr "abc"L_0006: stloc.0 L_0007: br.s L_0009L_0009: ldloc.0 L_000a: ret
}
public string Name{get{return "1";}}
//name是在接定口定義的:
//多了newslot virtual final 這幾個.
// .method public hidebysig specialname newslot virtual final instance string get_Name() cil managed {.maxstack 8L_0000: ldstr "1"L_0005: ret } int ITest.Age{get{return 1;}set{}} //age是顯示式實現的:
//不同點是用private修飾.其他的同上.get與set無區別. .method private hidebysig specialname newslot virtual final instance void System.Reflection.ITest.set_Age(int32 'value') cil managed {.override System.Reflection.ITest::set_Age.maxstack 8L_0000: nop L_0001: ret } .method private hidebysig specialname newslot virtual final instance int32 System.Reflection.ITest.get_Age() cil managed {.override System.Reflection.ITest::get_Age.maxstack 1.locals init ([0] int32 num)L_0000: nop L_0001: ldc.i4.1 L_0002: stloc.0 L_0003: br.s L_0005L_0005: ldloc.0 L_0006: ret }} //c#中的:abstract
.method public hidebysig specialname newslot abstract virtual instance string get_Tel() cil managed { } //C#中的virtual
.method public hidebysig specialname newslot virtual instance string get_Memo() cil managed {.maxstack 1.locals init ([0] string str)L_0000: nop L_0001: ldstr ""L_0006: stloc.0 L_0007: br.s L_0009L_0009: ldloc.0 L_000a: ret }
//name是在接定口定義的:
//多了newslot virtual final 這幾個.
// .method public hidebysig specialname newslot virtual final instance string get_Name() cil managed {.maxstack 8L_0000: ldstr "1"L_0005: ret } int ITest.Age{get{return 1;}set{}} //age是顯示式實現的:
//不同點是用private修飾.其他的同上.get與set無區別. .method private hidebysig specialname newslot virtual final instance void System.Reflection.ITest.set_Age(int32 'value') cil managed {.override System.Reflection.ITest::set_Age.maxstack 8L_0000: nop L_0001: ret } .method private hidebysig specialname newslot virtual final instance int32 System.Reflection.ITest.get_Age() cil managed {.override System.Reflection.ITest::get_Age.maxstack 1.locals init ([0] int32 num)L_0000: nop L_0001: ldc.i4.1 L_0002: stloc.0 L_0003: br.s L_0005L_0005: ldloc.0 L_0006: ret }} //c#中的:abstract
.method public hidebysig specialname newslot abstract virtual instance string get_Tel() cil managed { } //C#中的virtual
.method public hidebysig specialname newslot virtual instance string get_Memo() cil managed {.maxstack 1.locals init ([0] string str)L_0000: nop L_0001: ldstr ""L_0006: stloc.0 L_0007: br.s L_0009L_0009: ldloc.0 L_000a: ret }
?
?
| ? | 普通類 | 實現接口 |
| 1.屬性方法 | .method public hidebysig specialname instance string get_Address() cil managed | .method public hidebysig specialname instance newslot virtual final string get_Name() cil managed |
| 2.顯示實現 | ? | .method private hidebysig specialname instance newslot virtual final int32 System.Reflection.ITest.get_Age() cil managed |
| 3.Virtual | .method public hidebysig specialname instance newslot virtual string get_普通Virtual屬性() cil managed | .method public hidebysig specialname instance newslot virtual final沒了 string get_Memo() cil managed |
| 4.Abstract | .method public hidebysig specialname instance newslot abstract virtual ?string get_普通Abstract屬性() cil managed | .method public hidebysig specialname instance newslot abstract virtual string get_Tel() cil managed |
| 5.New | .method public hidebysig specialname instance 編譯時直接優化掉了. string get_普通未覆蓋基類屬性() cil managed | .method public hidebysig specialname instance newslot virtual final 與1相同 string get_接口NEW屬性() cil managed |
| ? | .method public hidebysig specialname instance //天哪,覆蓋基類中的new關鍵字只是個c#中的語法il不管這事,編譯時將被調用方法直接找到了? string get_覆蓋基類屬性() cil managed ? | ? |
?
?
下面是ITest的定義.
public interface ITest {// Propertiesint Age { get; set; }string Name { get; } }?
轉載于:https://www.cnblogs.com/foreachlife/p/msil1.html
總結
- 上一篇: 【博客园2018总结帖】21天,在Git
- 下一篇: [Vuex系列] - Mutation的