intermediate language - .NET IL Property setter -


consider class:

public class foo {     // fields     private string _bar;      // properties     private string bar     {                 {             return this._bar;         }         set         {             this._bar = value;         }     } } 

now when go , in il code emitted compiler setter of bar property:

.method private hidebysig specialname instance void set_bar(string 'value') cil managed {     .maxstack 8     l_0000: nop      l_0001: ldarg.0      l_0002: ldarg.1      l_0003: stfld string consoleapplication2.program/foo::_bar     l_0008: ret  } 

why ldarg.0 ? located in first (index 0) argument? since method/property setter takes 1 argument...

the same goes getter:

.method private hidebysig specialname instance string get_bar() cil managed {     .maxstack 1     .locals init (         [0] string cs$1$0000)     l_0000: nop      l_0001: ldarg.0      l_0002: ldfld string consoleapplication2.program/foo::_bar     l_0007: stloc.0      l_0008: br.s l_000a     l_000a: ldloc.0      l_000b: ret  } 

why .locals init ? why ldarg.0 ? why doesn't ldfld of backing field , return that? :)

thanks.

-snake

for setter:

any instance member has implicit "this" parameter - that's what's being loaded, basically. try turning static property , you'll see go away.

for getter, i'm not sure why there's local variable... debugger support perhaps? compiling in optimized mode (/o+ /debug- command line) gets rid of local variable.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -