views:

57

answers:

3

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.

+2  A: 

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.

Hans Passant
Hm ... good info, I am willing to mess with it. All I have to do is open a dialog, then change a label and change it back - it should then save the file in a format which is closer to what I want.
Hamish Grubijan
+1  A: 

There are some good comments here but it doesn't go so far to be StyleCop-compliant. What you need is this:

/// <summary>
/// Releases the unmanaged resources used by this
/// class and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">True to release both managed and unmanaged
/// resources; false to release only unmanaged resources.</param>

Hope this helps!

Jesse C. Slicer
Good stuff, but wanted to double-check - this particular comment would be appropriate in general cases, or only when I actually do interface with unmanaged stuff, such as using a `C# -> C++/CLI -> C++` bridge?
Hamish Grubijan
I generally leave this comment alone and also code up the finalizer too, but then comment it out if I know my class won't be using unmanaged resources. So if you're doing mostly unmanaged stuff, then the comment above as well as the Microsoft link will suffice for your cases.
Jesse C. Slicer
+1  A: 

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.

Philip Smith
It does fin them usually, but are they to be trusted, or to be used as a template only?
Hamish Grubijan
If your override does the job the comments state, then they can be used as is. If you change the behaviour then you will need to amend the comments to suit.
Philip Smith