Resharper建议Page_Load = PageLoad

And*_*hns 14 resharper naming-conventions pageload

通常当Page_LoadVisual Studio 将事件处理程序添加到代码隐藏文件时(例如,在设计器模式下双击页面),它最终看起来像这样:

/// <summary>
/// Handles the Load event of the Page 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 Page_Load(object sender, EventArgs e)
{
    // ...
}
Run Code Online (Sandbox Code Playgroud)

但是Resharper建议道Name 'Page_Load' does not match rule 'Methods, properties and events'. Suggested name is 'PageLoad'.我猜有一种更好的方法来定义页面加载的处理程序,但我不记得语法是什么,但我想它会解决这个Resharper警告?

也许是这样的:

/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
/// </summary>
/// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    // ...
}
Run Code Online (Sandbox Code Playgroud)

但我似乎记得,OnLoadPageLoad不完全一样?

Aak*_*shM 44

为了完整起见,我想我会在这里添加你在jetbrains.net上询问时从一个"David Benson"得到的答案:

如果您转到ReSharper选项,请在语言下选择C#命名样式.选择高级设置...按钮,然后在中Event subscriptions on fields:删除它所On在的前面.这应该删除警告.$event$$object$_$event$

对我来说,这是面对大型现有Web应用程序代码库来安抚ReSharper的最简单方法.

  • 恕我直言,这是问题的正确答案(+1因为它帮助了我) (2认同)

Chr*_*uts 7

OnLoad并且Page_Load 基本相同的.Page_Load如果在Page.上启用了AutoEventWireup,则通过反射调用.OnLoad是类的受保护虚拟方法Control(Page类继承).

请参阅Inside AutoEventWireup,深入分析AutoEventWireup的工作原理及其存在的原因.

在StackOverflow的社区也有一些投入 是否 更好地处理Load事件或重写OnLoad方法.