简体   繁体   English

哪种C#类型名称特别?

[英]Which C# type names are special?

Under what inputs does IsSpecialName return true? 在什么输入下IsSpecialName返回true? From my brief research I've found that property accessors and operator overloads have special names, alongside any type with a name which contains an underscore. 根据我的简短研究,我发现属性访问器和运算符重载具有特殊名称,以及名称包含下划线的任何类型。 Can anyone give me a complete description of cases in which a type name is special? 任何人都可以给我一个类型名称特殊的案例的完整描述吗?

The CLI specification as published in ECMA-335 is a decent source for info like this. ECMA-335中发布的CLI规范是这样的信息的合适来源。 Search the document for rtspecialname (names that are special to the CLR) and specialname (names that are special to tools. The specialname attribute is turned on for rtspecialnames. Giving these hits: 搜索文档rtspecialname (名称是特殊的CLR)和specialname类的特殊工具(名的specialname属性开启rtspecialnames给这些命中。:

  • The underlying value__ field of an enumerated type 枚举类型的基础value__字段
  • The getter and setter accessor methods of a property 属性的getter和setter访问器方法
  • The add, remove and fire accessors methods of an event 事件的add,remove和fire访问器方法
  • Operator overloads 运算符重载
  • The .ctor method of a class, the constructor 类的.ctor方法,构造函数
  • The .cctor method of a class, the static constructor 类的.cctor方法,静态构造函数

First of all IsSpecialName does not take any input. 首先,IsSpecialName不接受任何输入。 Also the property of Type is not really applicable to property accessors or operator overloads, since it's a property of a Type and operators/accessors are not types. Type的属性也不适用于属性访问器或运算符重载,因为它是Type的属性,而operator / accessors不是类型。 This is despite what the MSDN article might tell you. 尽管MSDN文章可能会告诉您这一点。

I would venture a guess that it returns true when the correspondent TypeAttribute is SpecialName . 我猜想当对应的TypeAttributeSpecialName时它会返回true。 You can refer to ECMA 335 Standard to find out what is supposed to be marked as a Special Name. 您可以参考ECMA 335标准,找出应该标记为特殊名称的内容。 Incidentally, you'll learn that it's things like operators and property accessors. 顺便说一下,你会发现它是运营商和财产访问者之类的东西。 This explains where the confusion in the MSDN article can come from. 这解释了MSDN文章中的混淆可能来自何处。

I believe that on Type this property is implemented mostly for the benefit of compilers and such that could require additional (as compared to what ECMA 335 mandate) special name handling. 我相信在Type这个属性主要是为了编译器的利益而实现的,这可能需要额外的(与ECMA 335的命令相比)特殊名称处理。 (Which could differ from compiler to compiler). (这可能因编译器而异)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM