Comments
1 comment
-
Those variables are in the code usually due to a debug build but sometimes the compiler needs to create a temp variable ... so it names it like that. Usually the Reflector translator can determine that it isn't needed and you won't see it in the C# translation - but in your case it is left over unoptimized code that Reflector didn't optimize out. If you change your optimization settings to None (View->Options->Optimization drop down), you'll see a lot more of these.
For example, the following code:
public class TestA
{
private string x;
public string TestX
{
get { return x; }
}
}
In debug version the property getter looks like this (notice the local variable CS$1$00000):
////////////////////////////////////////////////////////////
.method public hidebysig specialname instance string
get_TestX() cil managed
{
// Code size 12 (0xc)
.maxstack 1
.locals init ([0] string CS$1$0000)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld string Snippet/TestA::x
IL_0007: stloc.0
IL_0008: br.s IL_000a
IL_000a: ldloc.0
IL_000b: ret
} // end of method TestA::get_TestX
////////////////////////////////////////////////////////////
The release version looks like this:
////////////////////////////////////////////////////////////
.method public hidebysig specialname instance string
get_TestX() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld string Snippet/TestA::x
IL_0006: ret
} // end of method TestA::get_TestX
////////////////////////////////////////////////////////////
So the short story is ... those variables are in there either due to your compiler and then Reflector not optimizing them out in translating to C# - though Reflector does optimize a lot of them out such as in the property getter above - that CS$ variable will get optimized out unless you set the Optimize=None.
Add comment
Please sign in to leave a comment.
Is this a bug in .NET Reflector or is there a reason for this?