Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose and Meaning of "specialname" and "rtspecialname" in IL [duplicate]

Tags:

c#

il

ildasm

I am trying to understand the IL code and C# internals specifically nowadays, i wrote a simple c# hello world program whose code is :

using System;
class Program
{
    public static void Main()
    {
       Console.WriteLine("Hello World");
    }
}

and here is IL generated for the constuctor of Program class :

.method public hidebysig specialname rtspecialname 
        instance void  .ctor() cil managed
{
  // Code size       7 (0x7)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
  IL_0006:  ret
} // end of method Program::.ctor

I am not able to understand what is the meaning and purpose of specialname and rtspecialname or what's the use of them ?

like image 668
Ehsan Sajjad Avatar asked Dec 01 '15 17:12

Ehsan Sajjad


1 Answers

Per the ECMA 335 standard:

rtspecialname indicates that the name of this item has special significance to the CLI. There are no currently defined special type names; this is for future use. Any item marked rtspecialname shall also be marked specialname.

specialname indicates that the name of this item can have special significance to tools other than the CLI. See, for example, Partition I .

These attributes are used either by tools or the runtime to determine if an attribute or method has a special use or significance - one example (What other neat tricks does the SpecialNameAttribute allow?) is to mark an operator to prevent collisions with the user namespace. Another one I see in the standard is for getters and setters of properties, and it appears that the Main method you cited is another example.


Although I marked the original question as a duplicate, this question is slightly different in scope and the answer here might shed some more light. I hope anyway.

like image 63
Dan Field Avatar answered Nov 20 '22 21:11

Dan Field