为什么visual studio打破了C#中方法的命名约定?

the*_*drs 9 c# naming-conventions visual-studio

我知道C#中类方法的命名约定是以大写字母开头,每个新单词都是大写字母(例如GetDeviceName).

所以我的问题是为什么当我创建一个表单时,在其上放置一个控件,然后双击该控件(对于由IDE自动为我创建的方法)我得到一个以非大写字母开头的方法?(例如s electButton_Click(object sender,EventArgs e))

ang*_*son 11

控件的事件处理程序的命名约定一直是controlName_EventName,所以基本上,它重用您自己的控件命名约定,然后塞进事件的名称.

这可能与一般的命名标准相反,但它一直都是这样.

这样做的结果是,像GhostDoc这样的工具可以识别这种格式,从而生成一些文档,虽然它们仍然是通用的,但它更像是试图自己推断方法的目的.

例如,"controlName_EventName"方法可以这样记录:

/// <summary>
/// Handles the EventName event of the controlName control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance
/// containing the event data.</param>
protected void controlName_EventName(object sender, EventArgs e)
{
Run Code Online (Sandbox Code Playgroud)

而不是更像这样(因为GhostDoc处理上述问题,我根据对不良方法名称的经验在这里进行了解释):

/// <summary>
/// Control names the event name.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
protected void controlName_EventName(object sender, EventArgs e)
{
Run Code Online (Sandbox Code Playgroud)