"specialname" 和 "rtspecialname" 在 IL 中的用途和含义

Purpose and Meaning of "specialname" and "rtspecialname" in IL

我现在特别想了解 IL 代码和 C# 内部结构,我写了一个简单的 c# hello world 程序,其代码是:

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

这是为 Program class 的构造函数生成的 IL:

.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

我无法理解 specialnamertspecialname 的含义和用途,或者它们有什么用?

根据 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 .

工具或运行时使用这些属性来确定属性或方法是否具有特殊用途或意义 - 一个示例 (What other neat tricks does the SpecialNameAttribute allow?) 是标记运算符以防止与用户命名空间发生冲突.我在标准中看到的另一个是属性的 getter 和 setter,您引用的 Main 方法似乎是另一个例子。


虽然我将原始问题标记为重复,但这个问题的范围略有不同,这里的答案可能会更清楚一些。无论如何我希望。