浅谈团队开发命名规范
1. 大写
1.1. Pascal风格
变量的 首写字母大写,如:Credit ;
1.2. 驼峰规则
除了首个单词,每个单词的首字母大写,如:myNoteBook;
1.3. 大写风格
只在少于两个字母的缩写中使用大写。三个以上字母的缩写都应该使用PASCAL风格。
2. 命名方法
通常我们采用匈牙利命名法来为变量命名。
匈牙利命名法通常采用变量类型的缩写作为前缀,变量含义的全拼作为后缀的方法来命名变量。这种命名方法被广泛的采用在windows程序开发中,它因由一匈牙利程序员创立而得名。
注意:好的变量命名不是突出其类型,而是突出其含义。
对于UI控件,我们强制要求缩写前缀,例如:
System.Windows.Forms.Button btnCancel;
System.Windows.Forms.TextBox txtName;
2.1. 类命名
* 使用名词或名词短语命名类;
* 使用Pascal风格 ;
* 谨慎使用缩写命名类;
* 不要使用任何类前缀(如C)。
2.2. 接口命名
* 使用名词或名词短语命名接口.(例如 IIterator或 IEnumberable) ;
* 使用Pascal风格;
* 使用大写的I作为首字母,表示为接口。
2.3. 枚举命名
* 使用Pascal风格;
* 不使用前缀;
* 使用单数名词命名。
2.4. 常量命名
* 采用有意义的单词命名;
* 使用全部大写字母拼写。
2.5. 参数命名
* 相对变量而言,参数更注重本身的含义作为命名;
* 使用驼峰规则命名。
2.6. 变量命名
* 作为循环中的运算子的变量,更适合采用简单的命名,如i, j, k, l, m, n 。
2.7. 方法命名
* 采用动词命名,或者动词词组;
* 使用Pascal风格。
2.8. 属性命名
* 使用名词或名词短语命名属性;
* 使用Pascal风格。
2.9. 事件命名
* 使用EventHandler作为事件句柄的后缀;
* 使用两个参数:sender 和e;
* 使用Pascal风格;
* 使用EventArgs 作为Event Argument类型名的后缀;
* 使用进行时动词和过去式动词作为事件的名称。
2.10. 大写风格
Type |
Case |
Notes |
|
Class / Struct |
Pascal Casing |
|
|
Interface |
Pascal Casing |
Starts with I |
|
Enum values |
Pascal Casing |
|
|
Enum type |
Pascal Casing |
|
|
Events |
Pascal Casing |
|
|
Exception class |
Pascal Casing |
End with Exception |
|
public Fields |
Pascal Casing |
|
|
Methods |
Pascal Casing |
|
|
Namespace |
Pascal Casing |
|
|
Property |
Pascal Casing |
|
|
Protected/private Fields |
Camel Casing |
|
|
Parameters |
Camel Casing |
|
|
2.11. 常用控件缩写
标准控件 |
|
Button |
btn |
CheckBox |
chk |
CheckedListBox |
ckl |
ComboBox |
cmb |
DateTimePicker |
dtp |
Label |
lbl |
LinkLabel |
llb |
ListBox |
lst |
ListView |
lvw |
MaskedTextBox |
mtx |
MonthCalendar |
cdr |
NotifyIcon |
icn |
NumeircUpDown |
nud |
PictureBox |
pic |
ProgressBar |
prg |
RadioButton |
rdo |
RichTextBox |
rtx |
TextBox |
txt |
ToolTip |
tip |
TreeView |
tvw |
WebBrowser |
wbs |
容器控件 |
|
FlowLayoutPanel |
flp |
GroupBox |
grp |
Panel |
pnl |
SplitContainer |
spl |
TabControl |
tab |
TableLayoutPanel |
tlp |
菜单和工具栏 |
|
ContextMenuStrip |
cms |
MenuStrip |
mns |
StatusStrip |
ssr |
ToolStrip |
tsr |
ToolStripContainer |
tsc |
数据 |
|
DataSet |
dts |
DataGridView |
dgv |
BindingSource |
bds |
BindingNavigator |
bdn |
ReportViewer |
rpv |
Repeater |
rpt |
对话框 |
|
ColorDialog |
cld |
FolderBrowserDialog |
fbd |
FontDialog |
fnd |
OpenFileDialog |
ofd |
SaveFileDialog |
sfd |
组件 |
|
BackgroundWorker |
bgw |
DirectoryEntry |
dre |
DirectorySearcher |
drs |
ErrorProvider |
err |
EventLog |
evl |
FileSystemWatcher |
fsw |
HelpProvider |
hlp |
ImageList |
img |
MessageQueue |
msq |
PerformanceCounter |
pfc |
Process |
prc |
SerialPort |
spt |
ServiceController |
scl |
Timer |
tmr |
印刷 |
|
PageSetupDialog |
psd |
PrintDialog |
prd |
PrintDocument |
pdc |
PrintPreviewControl |
prv |
PrintPreviewDialog |
ppd |
水晶报表 |
|
CrystalReportViewer |
crv |
ReportDocument |
rpd |
其他 |
|
DomainUpDown |
dud |
HScrollBar |
hsc |
PropertyGrid |
prg |
Splitter |
spl |
TrackBar |
trb |
VScrollBar |
vsc |