Why does the compiler automatically generate a Debugger attribute for an anonymous type?

When compiling a simple anonymous type, for example:

public class Test
{   
    public static void Main()
    {
        var my_anonymous = new { Name = "anonymous"};
    }
}

IL code has a Debugger attribute for each generated method of an anonymous type. for example for equals:

.method public hidebysig virtual instance bool 
          Equals(object 'value') cil managed
  {
    .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
  ... // rest of IL code

Why does the compiler automatically generate it? I compiled it using Microsoft (R) Visual C # Compiler version 4.6.1055.0 and (if that matters) without using VS cmd.

Note. this answer is to remove the attribute (not possible), but I'm wondering about “Why?”.

+4
source share
3 answers

DebuggerHiddenAttribute - Visual Studio, , , ( - .)

- , , ( ) ( ) ).

+4

, , .

  • ; , - .
  • , , , .
  • , , .
+5

MSDN

. . , Visual Studio 2005 , . , Visual Studio 2005 DebuggerNonUserCodeAttribute DebuggerStepThroughAttribute.

I think this is added because the code is generated at compile time, not written by the programmer, so some lines of the generated code do not exist in the user code and the debugger may not show it.

0
source

Source: https://habr.com/ru/post/1653158/


All Articles