寻找 Stylecop 完美注释“protected override void Dispose(bool disducing)”
我知道,StyleCop
并不完美,但我们尝试以有用的方式使用它。我确实喜欢它抱怨未记录的论点。现在,对于属性和构造函数,它建议文本应该是什么,但它对 Dispose
方法没有帮助,但我认为应该如此。我们有许多实现IDisposable
的类。在这种特殊情况下,该类是一个WinForm
。问题是我无法为 Dispose
方法提供很好的文档,而且我也没有在网上看到一个很好的例子。许多例子没有任何评论。我希望那些觉得 Dispose
方法是他们的第二天性的人,可以帮助我一劳永逸地记录这一点,以便我可以在任何地方重复使用这个评论。
这是我们所得到的:
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.components != null)
{
this.components.Dispose();
}
}
base.Dispose(disposing);
}
这是警告消息:
Warning 15 SA1611: The documentation header must contain param tags matching the element's parameter list.
我希望其他 So 用户也会发现这个问题的答案也很有帮助。 如果您有疑问,请告诉我。
I know, StyleCop
is not perfect, but we try to use it in a helpful way. I do like the fact that it complains about undocumented arguments. Now, for properties and constructors it recommends what the text should be, but it does not help with Dispose
method, and I think it should. We have many classes that implement IDisposable
. In this particular case the class is a WinForm
. The trouble is that I have not been able to come up with great documentation for the Dispose
method, and I have not seen a good example online either. Many examples have no comment whatsoever. I am hoping that someone who feels like Dispose
method is a second nature to them, can help me document this once and for all, so that I can re-use this comment everywhere.
Here is what we have:
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (this.components != null)
{
this.components.Dispose();
}
}
base.Dispose(disposing);
}
And here is the warning message:
Warning 15 SA1611: The documentation header must contain param tags matching the element's parameter list.
I hope that other So users will find the answer to this helpful as well.
Let me know if you have questions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是从项目模板自动生成的代码。唯一真正的修复方法是更改模板或编辑 Designer.cs 源代码文件。模板位于 Common7\IDE\ItemsTemplate(Cache)\CSharp\Windows Forms\xxxx\Form.zip\form.designer.cs 中。编辑它当然只会解决未来项目的问题。
编辑自动生成的代码通常不是最好的主意,但在这种特殊情况下您会侥幸逃脱。
This is auto-generated code from a project template. The only real fix is to alter the template or edit the Designer.cs source code file. The template is in Common7\IDE\ItemsTemplate(Cache)\CSharp\Windows Forms\xxxx\Form.zip\form.designer.cs. Editing it will of course only fix the problem for future projects.
Editing auto-generated code isn't normally the greatest idea, but you'll get away with it in this particular case.
此处有一些很好的评论,但没有到目前为止符合 StyleCop。您需要的是:
希望这会有所帮助!
There are some good comments here but it doesn't go so far to be StyleCop-compliant. What you need is this:
Hope this helps!
您可以使用 GhostDoc 进行调查。它经常会搜索继承树并查找父类的注释。在这种情况下,当 Dispose 方法被重写时,它将找到有意义的注释。
You could investigate using GhostDoc. It will often search through the the inheritance tree and find comments from parent classes. In this case as the Dispose method is overridden it would find meaningful comments.