如何在 class 个名字中使用大写字母单词?

How to use capital letter words in class names?

我目前正在为一位使用大量缩写词(例如 "ABC"、"PTR")的客户开展项目。这些缩写在客户的语言中如此融合,以至于他们常常不知道缩写的完整形式实际上是什么。

我们通常会在 class 名称中使用这些词。但是这里的做法因开发人员而异,这导致了很多不同的命名约定。

使用大写首字母 (Abc) 或全部大写 (ABC) 会有所不同。我还观察到,当单词出现在 class 名称的中间时,相同的开发人员可能会使用全部大写,但如果单词出现在 class 名称的第一个单词中,则只使用首字母大写。

今天完成此操作的各种方式的一些虚构示例:

ABCHandler.cs

MapABCToPTR.cs

AbcModule.cs

DoSomeAbcRelatedWork.cs

class 名称(以及方法 ++)中所有大写单词的使用约定是什么?

根据 Microsofts naming guidelines 你可以将 two-letter-abbreviations 大写,但是 camel-case/pascal-case 一切都更长:

The PascalCasing convention, used for all identifiers except parameter names, capitalizes the first character of each word (including acronyms over two letters in length), as shown in the following examples:

PropertyDescriptor HtmlTag

A special case is made for two-letter acronyms in which both letters are capitalized, as shown in the following identifier: IOStream